4
* Created on: 25.11.2010
20
pkgmirror::pkgmirror(int fd): tCacheMan(fd),
21
m_bCalcSize(false), m_bSkipIxUpdate(false), m_bDoDownload(false),
24
m_sTypeName="Mirroring";
27
pkgmirror::~pkgmirror()
31
bool pkgmirror::ProcessRegular(const string &sPath, const struct stat &stinfo)
33
if (endsWithSzAr(sPath, ".head"))
36
if (sPath.size() <= CACHE_BASE_LEN) // heh?
39
if (0 == sPath.compare(CACHE_BASE_LEN, 1, "_"))
40
return true; // not for us, also includes _import
42
AddIFileCandidate(sPath.substr(CACHE_BASE_LEN));
44
return ! CheckAbortCondition();
47
tStrDeq GetVariants(cmstring &mine)
51
for(cmstring *p=suxeWempty; p<suxeWempty+_countof(suxeWempty); p++)
53
if(endsWith(mine, *p))
55
base=mine.substr(0, mine.size()-p->size());
59
for(cmstring *p=suxeWempty; p<suxeWempty+_countof(suxeWempty); p++)
68
void pkgmirror::Action(const string &cmd)
70
SendChunk("<b>Locating index files, scanning...</b><br>\n");
72
SetCommonUserFlags(cmd);
73
m_bErrAbort=false; // does not f...ing matter, do what we can
75
m_bCalcSize=(cmd.find("calcSize=cs")!=stmiss);
76
m_bDoDownload=(cmd.find("doDownload=dd")!=stmiss);
77
m_bSkipIxUpdate=(cmd.find("skipIxUp=si")!=stmiss);
79
DirectoryWalk(acfg::cachedir, this);
81
if(CheckAbortCondition())
84
if(m_indexFilesRel.empty())
86
SendChunk("<font size=0 color=red>No index files detected. Unable to continue, cannot map files to internal locations.</font>");
90
if(CheckAbortCondition())
97
if(CheckAbortCondition())
101
class __srcpicker : public ifileprocessor
106
__srcpicker(tStrSet *x) : pSrcs(x)
108
Tokenize(acfg::mirrorsrcs, SPACECHARS, matchList);
110
void TryAdd(cmstring &s)
112
for(tStrVecIterConst it=matchList.begin(); it!=matchList.end(); it++)
113
if(0==fnmatch(it->c_str(), s.c_str(), FNM_PATHNAME))
119
void HandlePkgEntry(const tRemoteFileInfo &entry, bool)
121
TryAdd(entry.sDirectory+entry.sFileName);
127
for(tS2IDX::iterator it=m_indexFilesRel.begin(); it!=m_indexFilesRel.end();it++)
129
if(endsWithSzAr(it->first, "Release"))
131
if(!GetFlags(it->first).uptodate)
132
if(!DownloadIdxFile(it->first, sErr))
133
SendFmt() << "<font color=\"red\">" << sErr << "</font><br>\n";
134
ParseAndProcessIndexFile(picker, it->first, EIDX_RELEASE);
137
picker.TryAdd(it->first);
140
SendChunk("<b>Identifying relevant index files...</b><br>");
142
// unless found in release files, get the from the local system
143
for (tStrVecIterConst it = picker.matchList.begin(); it != picker.matchList.end(); it++)
145
tStrDeq paths(ExpandFilePattern(CACHE_BASE+it->c_str(), false));
146
for(tStrDeq::iterator j=paths.begin(); j!=paths.end(); j++)
150
restart_clean: // start over if the set changed while having a hot iterator
151
for(tStrSet::iterator it=srcs.begin(); it!=srcs.end(); it++)
153
if(GetFlags(*it).uptodate) // this is the one
155
tStrDeq bros(GetVariants(*it));
157
for(tStrDeq::iterator b=bros.begin(); b!=bros.end(); b++)
158
nDeleted+=srcs.erase(*b);
164
// now there may still be something like Sources and Sources.bz2 if they
165
// were added by Release file scan. Choose the prefered simply by extension.
167
restart_clean2: // start over if the set changed while having a hot iterator
168
for (const string *p = suxeByCompSize; p < suxeByCompSize
169
+ _countof(suxeByCompSize); p++)
171
for (tStrSet::iterator it = srcs.begin(); it != srcs.end(); it++)
173
if(endsWith(*it, *p))
175
tStrDeq bros(GetVariants(*it));
177
for(tStrDeq::iterator b=bros.begin(); b!=bros.end(); b++)
178
nDeleted+=srcs.erase(*b);
185
for (tStrSet::iterator it=srcs.begin(); it!=srcs.end(); it++)
187
SendFmt() << "File list: " << *it<< "<br>";
188
if(!GetFlags(*it).uptodate)
189
DownloadIdxFile(*it, sErr);
191
if(CheckAbortCondition())
200
SendChunk("<b>Counting downloadable content size...</b><br>");
201
for (tStrSet::iterator it = srcs.begin(); it != srcs.end(); it++)
203
class __cnt: public ifileprocessor
212
void HandlePkgEntry(const tRemoteFileInfo &entry, bool)
214
sum += entry.fpr.size;
215
have += GetFileSize(CACHE_BASE + entry.sDirectory + entry.sFileName, 0);
216
//off_t have=GetFileSize(CACHE_BASE+entry.sDirectory+entry.sFileName, 0);
217
//sum+=(entry.fpr.size-have);
221
ParseAndProcessIndexFile(counter, *it, GuessIndexType(*it));
223
SendFmt() << *it << ": " << offttosH(counter.sum - counter.have) << "/" << offttosH(
224
counter.sum) << "<br>\n";
225
total += counter.sum;
226
m_totalneed += (counter.sum - counter.have);
228
if(CheckAbortCondition())
231
SendFmt() << "Total size: " << offttosH(total) << ", missing: up to "
232
<< offttosH(m_totalneed) << "<br>\n";
235
if(m_bDoDownload && (m_totalneed>0 || !m_bCalcSize))
237
SendChunk("<b>Starting download...</b><br>");
239
for (tStrSet::iterator it=srcs.begin(); it!=srcs.end(); it++)
241
if(CheckAbortCondition())
244
ParseAndProcessIndexFile(*this, *it, GuessIndexType(*it));
250
void pkgmirror::UpdateFingerprint(const mstring &sPathRel, off_t nOverrideSize,
251
uint8_t *pOverrideSha1, uint8_t *pOverrideMd5)
256
void pkgmirror::HandlePkgEntry(const tRemoteFileInfo &entry, bool bUncompressForChecksum)
260
davor=GetFileSize(CACHE_BASE + entry.sDirectory + entry.sFileName, 0);
262
DownloadSimple(entry.sDirectory+entry.sFileName);
266
off_t diff=(GetFileSize(CACHE_BASE + entry.sDirectory + entry.sFileName, 0)-davor);
267
if(m_totalneed && diff)
270
SendFmt() << "Remaining download size: " << offttosH(m_totalneed)<< "<br>\n";