47 struct LsTreeEntry_t {
53 LsTreeEntry_t(
const char *g,
const char *u,
const char *cs,
const char *ls, Long64_t m) :
54 fMtime(m) { fGrp =
new TObjString(g); fUsr =
new TObjString(u);
55 fMd5 =
new TObjString(cs); fLss =
new TObjString(ls); }
56 ~LsTreeEntry_t() { SafeDelete(fGrp); SafeDelete(fUsr); SafeDelete(fMd5); SafeDelete(fLss);}
59 ClassImp(TDataSetManagerFile);
65 TDataSetManagerFile::TDataSetManagerFile(
const char *group,
66 const char *user,
const char *ins)
67 : TDataSetManager(group, user, ins)
80 TDataSetManagerFile::TDataSetManagerFile(
const char *ins)
81 : TDataSetManager(
"",
"", ins)
93 void TDataSetManagerFile::Init()
96 if (!fUser.IsNull() && !fGroup.IsNull() && !fDataSetDir.IsNull()) {
100 dir.Form(
"%s/%s/%s", fDataSetDir.Data(), fGroup.Data(), fUser.Data());
101 if (gSystem->AccessPathName(dir)) {
102 if (gSystem->mkdir(dir, kTRUE) != 0) {
106 fGroup = fCommonGroup;
107 ResetBit(TDataSetManager::kCheckQuota);
108 ResetBit(TDataSetManager::kAllowRegister);
109 ResetBit(TDataSetManager::kAllowVerify);
110 ResetBit(TDataSetManager::kTrustInfo);
111 dir.Form(
"%s/%s/%s", fDataSetDir.Data(), fGroup.Data(), fUser.Data());
112 if (gSystem->AccessPathName(dir)) {
114 "could not attach to a valid the dataset dir; paths tried:");
115 Error(
"Init",
" %s", emsg.Data());
116 Error(
"Init",
" %s", dir.Data());
117 SetBit(TObject::kInvalidObject);
121 else if (fOpenPerms) {
127 t.Form(
"%s/%s/%s", fDataSetDir.Data(), fGroup.Data(), fUser.Data());
128 rr += gSystem->Chmod(t.Data(), 0777);
130 t.Form(
"%s/%s", fDataSetDir.Data(), fGroup.Data());
131 rr += gSystem->Chmod(t.Data(), 0777);
133 rr += gSystem->Chmod(fDataSetDir.Data(), 0777);
136 t.Form(
"%s/%s/%s", fDataSetDir.Data(), fGroup.Data(),
139 "problems setting perms of dataset directory %s (#%d)",
140 t.Data(), TSystem::GetErrno());
148 if (!TestBit(TDataSetManager::kIsSandbox))
149 fBase.SetUri(TString(Form(
"/%s/%s/", fGroup.Data(), fUser.Data())));
153 TFile::EFileType pathType = TFile::GetType(fDataSetDir,
"READ", &locPath);
154 if (pathType == TFile::kLocal) {
156 fDataSetDir = locPath;
158 Info(
"Init",
"repository '%s' is local", fDataSetDir.Data());
159 }
else if (pathType != TFile::kDefault && pathType != TFile::kFile) {
162 Info(
"Init",
"repository '%s' is remote", fDataSetDir.Data());
166 TString lockloc = TString::Format(
"%s/%s", fDataSetDir.Data(), kDataSet_LockLocation);
167 if (!gSystem->AccessPathName(lockloc, kReadPermission)) {
169 lockloc +=
"?filetype=raw";
170 TFile *f = TFile::Open(lockloc);
171 if (f && !(f->IsZombie())) {
172 const Int_t blen = 8192;
174 Long64_t rest = f->GetSize();
176 Long64_t len = (rest > blen - 1) ? blen - 1 : rest;
177 if (f->ReadBuffer(buf, len)) {
178 fDataSetLockFile =
"";
182 fDataSetLockFile += buf;
187 fDataSetLockFile.ReplaceAll(
"\n",
"");
189 lockloc.ReplaceAll(
"?filetype=raw",
"");
190 Warning(
"Init",
"could not open remore file '%s' with the lock location", lockloc.Data());
193 if (fDataSetLockFile.IsNull()) {
194 fDataSetLockFile.Form(
"%s-dataset-lock", fDataSetDir.Data());
195 fDataSetLockFile.ReplaceAll(
"/",
"%");
196 fDataSetLockFile.ReplaceAll(
":",
"%");
197 fDataSetLockFile.Insert(0, TString::Format(
"%s/", gSystem->TempDirectory()));
199 if (!fDataSetLockFile.IsNull() && fIsRemote) {
200 TUrl lu(fDataSetLockFile, kTRUE);
201 if (!strcmp(lu.GetProtocol(),
"file")) {
204 TString srv(fDataSetDir);
205 srv.Remove(srv.Index(u.GetFile()));
206 fDataSetLockFile.Insert(0, srv);
212 fLockFileTimeLimit = 120;
215 fCacheUpdatePeriod = gEnv->GetValue(
"ProofDataSet.CacheUpdatePeriod", 0);
218 if (fMSSUrl.IsNull())
219 fMSSUrl = gEnv->GetValue(
"ProofDataSet.MSSUrl",
"");
221 fStageOpts = gEnv->GetValue(
"DataSet.StageOpts",
"p=3");
224 fListFile.Form(
"%s/%s", fDataSetDir.Data(), kDataSet_DataSetList);
234 void TDataSetManagerFile::InitLocalCache()
236 fUseCache = (fIsRemote) ? kTRUE : kFALSE;
240 if (TestBit(TDataSetManager::kUseCache)) useCache =
"yes";
241 if (TestBit(TDataSetManager::kDoNotUseCache)) useCache =
"no";
242 if (useCache.IsNull()) useCache = gEnv->GetValue(
"DataSet.UseCache",
"");
243 if (useCache.IsNull() && gSystem->Getenv(
"DATASETCACHE"))
244 useCache = gSystem->Getenv(
"DATASETCACHE");
246 if (!useCache.IsNull())
247 fUseCache = (useCache ==
"no" || useCache ==
"0") ? kFALSE : kTRUE;
250 fLocalCacheDir = gSystem->Getenv(
"DATASETLOCALCACHEDIR");
251 if (fLocalCacheDir.IsNull())
252 fLocalCacheDir = gEnv->GetValue(
"DataSet.LocalCacheDir",
"");
253 if (!fLocalCacheDir.IsNull()) {
255 if (gSystem->AccessPathName(fLocalCacheDir)) {
256 if (gSystem->mkdir(fLocalCacheDir, kTRUE) != 0) {
258 Warning(
"InitLocalCache",
259 "non-default local cache directory '%s' could not be created"
260 " - switching to default", fLocalCacheDir.Data());
264 if (!fLocalCacheDir.IsNull() &&
265 gSystem->AccessPathName(fLocalCacheDir, kWritePermission)) {
266 Warning(
"InitLocalCache",
267 "non-default local cache directory '%s' is not writable"
268 " - switching to default",
274 if (fLocalCacheDir.IsNull()) {
276 TString uds(fDataSetDir.Data());
277 uds.ReplaceAll(
"/",
"%");
278 uds.ReplaceAll(
":",
"%");
279 if (TString(gSystem->TempDirectory()).EndsWith(fUser.Data())) {
280 fLocalCacheDir.Form(
"%s/%s/%s", gSystem->TempDirectory(),
281 kDataSet_LocalCache, uds.Data());
283 fLocalCacheDir.Form(
"%s/%s/%s/%s", gSystem->TempDirectory(),
284 fUser.Data(), kDataSet_LocalCache, uds.Data());
287 if (gSystem->AccessPathName(fLocalCacheDir) && gSystem->mkdir(fLocalCacheDir, kTRUE) != 0) {
289 Warning(
"InitLocalCache",
290 "local cache directory '%s' could not be created"
291 " - disabling cache", fLocalCacheDir.Data());
294 if (!fLocalCacheDir.IsNull() &&
295 gSystem->AccessPathName(fLocalCacheDir, kWritePermission)) {
296 Warning(
"InitLocalCache",
297 "local cache directory '%s' is not writable - disabling cache",
301 if (!fUseCache) fLocalCacheDir =
"";
317 void TDataSetManagerFile::ParseInitOpts(
const char *ins)
319 SetBit(TObject::kInvalidObject);
323 if (!ins || strlen(ins) <= 0)
return;
328 while (s.Tokenize(tok, from,
" ")) {
329 if (tok.BeginsWith(
"dir:"))
330 fDataSetDir = tok(4, tok.Length());
331 if (tok.BeginsWith(
"mss:"))
332 fMSSUrl = tok(4, tok.Length());
333 if (tok ==
"perms:open")
338 if (fDataSetDir.IsNull())
return;
341 ResetBit(TObject::kInvalidObject);
351 const char *TDataSetManagerFile::GetDataSetPath(
const char *group,
354 TString &md5path, Bool_t local)
356 if (fgCommonDataSetTag == group)
357 group = fCommonGroup;
359 if (fgCommonDataSetTag == user)
362 const char *ext = (!strcmp(dsName,
"ls")) ?
".txt" :
".root";
363 static TString result;
365 result.Form(
"%s/%s.%s.%s%s", fLocalCacheDir.Data(), group, user, dsName, ext);
366 md5path.Form(
"%s/%s.%s.%s.md5sum", fLocalCacheDir.Data(), group, user, dsName);
368 result.Form(
"%s/%s/%s/%s%s", fDataSetDir.Data(), group, user, dsName, ext);
369 md5path.Form(
"%s/%s/%s/%s.md5sum", fDataSetDir.Data(), group, user, dsName);
372 Info(
"GetDataSetPath",
"paths: %s, %s ", result.Data(), md5path.Data());
382 Int_t TDataSetManagerFile::NotifyUpdate(
const char *group,
const char *user,
383 const char *dsName, Long_t mtime,
const char *checksum)
389 if ((lsrc = CreateLsFile(group, user, lsmtime, lschecksum)) < 0) {
390 Warning(
"NotifyUpdate",
"problems (re-)creating the dataset lists for '/%s/%s'",
394 { TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
395 TString dspath = TString::Format(
"/%s/%s/%s", group, user, dsName);
397 Bool_t hasListFile = gSystem->AccessPathName(fListFile) ? kFALSE : kTRUE;
399 TMD5 *oldMd5 = 0, *newMd5 = 0;
400 if (hasListFile && !(oldMd5 = TMD5::FileChecksum(fListFile.Data()))) {
401 Error(
"NotifyUpdate",
"problems calculating old checksum of %s", fListFile.Data());
406 if (hasListFile) mac.ReadFile(fListFile.Data());
408 TObjString *os = mac.GetLineWith(dspath);
411 if (!strcmp(checksum,
"removed")) {
412 mac.GetListOfLines()->Remove(os);
416 os->SetString(TString::Format(
"%ld %s %s", mtime, dspath.Data(), checksum));
419 if (!strcmp(checksum,
"removed")) {
420 Warning(
"NotifyUpdate",
"entry for removed dataset '%s' not found!", dspath.Data());
423 mac.AddLine(TString::Format(
"%ld %s %s", mtime, dspath.Data(), checksum));
427 TString lspath = TString::Format(
"/%s/%s/ls", group, user);
428 os = mac.GetLineWith(lspath);
432 mac.GetListOfLines()->Remove(os);
436 os->SetString(TString::Format(
"%ld %s %s", lsmtime, lspath.Data(), lschecksum.Data()));
441 mac.AddLine(TString::Format(
"%ld %s %s", lsmtime, lspath.Data(), lschecksum.Data()));
445 mac.SaveSource(fListFile.Data());
447 if (gSystem->Chmod(fListFile.Data(), 0666) < 0) {
448 Warning(
"NotifyUpdate",
449 "can't set permissions of dataset list file %s (#%d)",
450 fListFile.Data(), TSystem::GetErrno());
453 if (!(newMd5 = TMD5::FileChecksum(fListFile.Data()))) {
454 Error(
"NotifyUpdate",
"problems calculating new checksum of %s", fListFile.Data());
458 if (oldMd5 && (*newMd5 == *oldMd5))
459 Warning(
"NotifyUpdate",
"checksum for %s did not change!", fListFile.Data());
474 Int_t TDataSetManagerFile::CreateLsFile(
const char *group,
const char *user,
475 Long_t &mtime, TString &checksum)
482 tmpfile.Form(
"%s/%s/%s/ls.tmp.txt", fDataSetDir.Data(), group, user);
486 if (gSystem->RedirectOutput(tmpfile.Data(),
"w", &rh) != 0) {
487 Error(
"CreateLsFile",
"problems redirecting output to %s (errno: %d)",
488 tmpfile.Data(), TSystem::GetErrno());
493 uri.Form(
"/%s/%s", group, user);
494 ShowDataSets(uri,
"forcescan:noheader:");
496 if (gSystem->RedirectOutput(0, 0, &rh) != 0) {
497 Error(
"CreateLsFile",
"problems restoring output to standard streams (errno: %d)",
498 TSystem::GetErrno());
502 TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
505 lsfile.Form(
"%s/%s/%s/ls.txt", fDataSetDir.Data(), group, user);
507 if (!gSystem->AccessPathName(lsfile) && gSystem->Unlink(lsfile) != 0) {
508 Error(
"CreateLsFile",
"problems unlinking old file '%s' (errno: %d)",
509 lsfile.Data(), TSystem::GetErrno());
514 if (gSystem->GetPathInfo(tmpfile, st) == 0 && st.fSize > 0) {
515 if (gSystem->Rename(tmpfile, lsfile) != 0) {
516 Error(
"CreateLsFile",
"problems renaming '%s' to '%s' (errno: %d)",
517 tmpfile.Data(), lsfile.Data(), TSystem::GetErrno());
523 if (!fIsRemote && gSystem->GetPathInfo(gSystem->DirName(tmpfile), udirst) == 0) {
524 if (chown(lsfile.Data(), udirst.fUid, udirst.fGid) != 0) {
525 Warning(
"CreateLsFile",
"problems setting ownership on file '%s' (errno: %d)",
526 lsfile.Data(), TSystem::GetErrno());
529 if (gSystem->Chmod(lsfile.Data(), 0666) < 0) {
530 Warning(
"NotifyUpdate",
531 "can't set permissions of list file %s (#%d)",
532 lsfile.Data(), TSystem::GetErrno());
535 else if (chmod(lsfile.Data(), 0644) != 0) {
536 Warning(
"CreateLsFile",
"problems setting permissions on file '%s' (errno: %d)",
537 lsfile.Data(), TSystem::GetErrno());
542 TMD5 *md5 = TMD5::FileChecksum(lsfile);
544 Error(
"CreateLsFile",
"problems calculating checksum for '%s'", lsfile.Data());
546 checksum = md5->AsString();
550 if (!gSystem->AccessPathName(tmpfile) && gSystem->Unlink(tmpfile) != 0) {
551 Error(
"CreateLsFile",
"problems unlinking temp file '%s' (errno: %d)",
552 tmpfile.Data(), TSystem::GetErrno());
577 Bool_t TDataSetManagerFile::BrowseDataSets(
const char *group,
const char *user,
579 UInt_t option, TObject *target)
582 userDirPath.Form(
"%s/%s/%s", fDataSetDir.Data(), group, user);
583 void *userDir = gSystem->OpenDirectory(userDirPath);
588 Bool_t printing = (option & kPrint) ? kTRUE : kFALSE;
589 Bool_t exporting = (option & kExport) ? kTRUE : kFALSE;
590 Bool_t updating = (option & kQuotaUpdate) ? kTRUE : kFALSE;
591 Bool_t printout = (printing && (option & kDebug)) ? kTRUE : kFALSE;
592 Bool_t listing = (option & kList) ? kTRUE : kFALSE;
595 if (printing || updating)
596 option |= kReadShort;
599 if (((Int_t)printing + (Int_t)exporting + (Int_t)updating + (Int_t)listing) > 1) {
600 Error(
"BrowseDataSets",
601 "only one of kPrint, kQuotaUpdate, kExport or kList can be specified at once");
604 Bool_t fillmap = (!exporting && !printing && !updating) ? kTRUE : kFALSE;
607 TMap *outmap = (fillmap || exporting || listing) ? (TMap *)target : (TMap *)0;
608 TList *outlist = (printing) ? (TList *)target : (TList *)0;
610 TRegexp rg(
"^[^./][^/]*.root$");
613 if (dsName && strlen(dsName) > 0) reds =
new TRegexp(dsName, kTRUE);
615 TMap *userMap = 0, *datasetMap = 0;
617 const char *dsEnt = 0;
618 while ((dsEnt = gSystem->GetDirEntry(userDir))) {
619 TString datasetFile(dsEnt);
620 if (datasetFile.Index(rg) != kNPOS) {
621 TString datasetName(datasetFile(0, datasetFile.Length()-5));
624 if (reds && datasetName.Index(*reds) == kNPOS)
continue;
627 Info(
"GetDataSets",
"found dataset %s of user %s in group %s",
628 datasetName.Data(), user, group);
630 TFileCollection *fileList = GetDataSet(group, user, datasetName, option);
632 Error(
"GetDataSets",
"dataset %s (user %s, group %s) could not be opened",
633 datasetName.Data(), user, group);
642 const char *mapGroup = group;
643 if (fCommonGroup == mapGroup)
644 mapGroup = fgCommonDataSetTag.Data();
645 const char *mapUser = user;
646 if (fCommonUser == mapUser)
647 mapUser = fgCommonDataSetTag.Data();
649 if (fillmap && !listing && outmap) {
650 if (!(userMap = dynamic_cast<TMap*> (outmap->GetValue(mapGroup)))) {
653 outmap->Add(
new TObjString(mapGroup), userMap);
656 if (!(datasetMap = dynamic_cast<TMap*> (userMap->GetValue(mapUser)))) {
657 datasetMap =
new TMap;
658 datasetMap->SetOwner();
659 userMap->Add(
new TObjString(mapUser), datasetMap);
667 TString dsNameFormatted(Form(
"/%s/%s/%s", mapGroup,
668 mapUser, datasetName.Data()));
670 outmap->Add(
new TObjString(dsNameFormatted), fileList);
672 }
else if (updating) {
675 GetQuota(mapGroup, mapUser, datasetName.Data(), fileList);
677 }
else if (printing) {
681 TString dsNameFormatted(Form(
"/%s/%s/%s", mapGroup,
682 mapUser, datasetName.Data()));
684 if (dsNameFormatted.Length() < 42)
685 dsNameFormatted.Resize(42);
688 outlist->Add(fileList->ExportInfo(dsNameFormatted));
691 TObjString *os = (TObjString *) outlist->Last();
692 if (os) Printf(
"%s", os->GetName());
695 }
else if (listing) {
699 outmap->Add(
new TObjString(TString::Format(
"/%s/%s/%s", mapGroup, mapUser, datasetName.Data())),
703 if (fillmap && datasetMap)
704 datasetMap->Add(
new TObjString(datasetName), fileList);
708 gSystem->FreeDirectory(userDir);
742 TMap *TDataSetManagerFile::GetDataSets(
const char *group,
const char *user,
743 const char *dsName, UInt_t option)
745 if (group && fgCommonDataSetTag == group)
746 group = fCommonGroup;
748 if (user && fgCommonDataSetTag == user)
752 Bool_t notCommonUser = kTRUE;
753 if ((user && fCommonUser == user) &&
754 (group && fCommonGroup == group)) notCommonUser = kFALSE;
757 if (group && (strcmp(group,
"*") == 0 || !group[0]))
759 if (user && (strcmp(user,
"*") == 0 || !user[0]))
762 Bool_t printing = (option & kPrint) ? kTRUE : kFALSE;
763 Bool_t forcescan = (option & kForceScan) ? kTRUE : kFALSE;
764 Bool_t printheader = (option & kNoHeaderPrint) ? kFALSE : kTRUE;
765 Bool_t exporting = (option & kExport) ? kTRUE : kFALSE;
766 Bool_t updating = (option & kQuotaUpdate) ? kTRUE : kFALSE;
767 Bool_t refreshingls = (option & kRefreshLs) ? kTRUE : kFALSE;
768 Bool_t listing = (option & kList) ? kTRUE : kFALSE;
771 if (((Int_t)printing + (Int_t)exporting + (Int_t)updating + (Int_t)listing) > 1) {
772 Error(
"GetDataSets",
"only one of '?P', '?Q', '?E' or '?L' can be specified at once");
779 TList *ol =
new TList();
782 }
else if (exporting || !updating || listing) {
789 Info(
"GetDataSets",
"opening dir %s", fDataSetDir.Data());
793 if (option & kShowDefault) {
796 if (CreateLsFile(fCommonGroup, fCommonUser, m, s) != 0)
797 Warning(
"GetDataSets",
"problems recreating 'ls' info for {%s,%s}",
798 fCommonGroup.Data(), fCommonUser.Data());
799 }
else if (!printing || forcescan || (printing &&
800 FillLsDataSet(fCommonGroup, fCommonUser, dsName, (TList *)result, option) != 0)) {
801 BrowseDataSets(fCommonGroup, fCommonUser, dsName, option, result);
806 if (!notCommonUser) notCommonUser = kTRUE;
812 if (user && group && strchr(user,
'*') && strchr(group,
'*')) {
814 if (CreateLsFile(group, user, m, s) != 0)
815 Warning(
"GetDataSets",
"problems recreating 'ls' info for {%s,%s}",
817 }
else if (!printing || forcescan || (printing &&
818 FillLsDataSet(group, user, dsName, (TList *)result, option) != 0)) {
819 BrowseDataSets(group, user, dsName, option, result);
821 if (!printing)
return (TMap *)result;
823 TRegexp *reg = (group && strlen(group) > 0) ?
new TRegexp(group, kTRUE) : 0;
824 TRegexp *reu = (user && strlen(user) > 0) ?
new TRegexp(user, kTRUE) : 0;
826 if (printing && !forcescan &&
827 fUseCache && CheckLocalCache(group, user, 0, option) == 0) {
830 TString locupdate, dsn, grp, usr;
831 locupdate.Form(
"%s/%s", fLocalCacheDir.Data(), kDataSet_DataSetList);
832 TMacro uptmac(locupdate);
833 TIter nxl(uptmac.GetListOfLines());
835 while ((os = (TObjString *) nxl())) {
836 if (!(os->GetString().Contains(
"/ls")))
continue;
838 if (!(os->GetString().Tokenize(dsn, from,
" ")))
continue;
839 if (!(os->GetString().Tokenize(dsn, from,
" ")))
continue;
842 if (!(dsn.Tokenize(grp, from,
"/")) || (reg && (grp.Index(*reg) == kNPOS)))
continue;
844 if (!(dsn.Tokenize(usr, from,
"/")) || (reu && (usr.Index(*reu) == kNPOS)))
continue;
846 if (FillLsDataSet(grp, usr, dsName, (TList *)result, option) != 0) {
848 BrowseDataSets(grp, usr, dsName, option, result);
853 void *dataSetDir = 0;
854 if ((dataSetDir = gSystem->OpenDirectory(fDataSetDir))) {
857 while ((eg = gSystem->GetDirEntry(dataSetDir))) {
859 if (strcmp(eg,
".") == 0 || strcmp(eg,
"..") == 0)
862 if (reg && (TString(eg).Index(*reg) == kNPOS))
865 TString groupDirPath;
866 groupDirPath.Form(
"%s/%s", fDataSetDir.Data(), eg);
870 if (gSystem->GetPathInfo(groupDirPath, dirSt) != 0 || !R_ISDIR(dirSt.fMode))
873 void *groupDir = gSystem->OpenDirectory(groupDirPath);
879 while ((eu = gSystem->GetDirEntry(groupDir))) {
881 if (strcmp(eu,
".") == 0 || strcmp(eu,
"..") == 0)
884 if (reu && (TString(eu).Index(*reu) == kNPOS))
889 if (CreateLsFile(eg, eu, m, s) != 0)
890 Warning(
"GetDataSets",
"problems recreating 'ls' info for {%s,%s}",
892 }
else if (!printing || forcescan || (printing &&
893 FillLsDataSet(eg, eu, dsName, (TList *)result, option) != 0)) {
895 BrowseDataSets(eg, eu, dsName, option, result);
898 gSystem->FreeDirectory(groupDir);
900 gSystem->FreeDirectory(dataSetDir);
909 TList *output = (TList *)result;
912 Printf(
"Dataset repository: %s", fDataSetDir.Data());
913 Printf(
"Dataset URI | # Files | Default tree | # Events | Disk | Staged");
917 while ((os = dynamic_cast<TObjString*> (iter4()))) {
918 if (os->GetString().BeginsWith(
"file:")) {
920 TString path(os->GetString()(5, os->GetString().Length()));
921 RedirectHandle_t rh(path.Data());
922 gSystem->ShowOutput(&rh);
926 Printf(
"%s", os->String().Data());
934 return (TMap *)result;
943 Int_t TDataSetManagerFile::FillLsDataSet(
const char *group,
const char *user,
944 const char *dsname, TList *out, UInt_t option)
947 if (!group || strlen(group) <= 0 || !user || strlen(user) <= 0 || !out) {
948 Error(
"FillLsDataSet",
"at least one of the inputs is invalid (%s,%s,%p)", group, user, out);
954 TString lsfile, lsmd5file;
955 if (!fUseCache || (fUseCache && (crc = CheckLocalCache(group, user,
"ls", option)) <= 0)) {
956 Bool_t local = (crc == 0) ? kTRUE : kFALSE;
957 lsfile = GetDataSetPath(group, user,
"ls", lsmd5file, local);
963 if (gSystem->AccessPathName(lsfile, kFileExists)) {
965 Info(
"FillLsDataSet",
"file '%s' does not exists", lsfile.Data());
968 if (gSystem->AccessPathName(lsfile, kReadPermission)) {
969 Warning(
"FillLsDataSet",
"file '%s' exists cannot be read (permission denied)", lsfile.Data());
973 if (dsname && strlen(dsname) > 0) {
975 TMacro *mac =
new TMacro(lsfile.Data());
977 Error(
"FillLsDataSet",
"could not initialize TMacro from '%s'", lsfile.Data());
981 TString fullname = TString::Format(
"/%s/%s/%s", group, user, dsname);
982 Bool_t wc = (fullname.Contains(
"*")) ? kTRUE : kFALSE;
983 if (wc) fullname.ReplaceAll(
"*",
".*");
984 TRegexp reds(fullname);
985 TIter nxl(mac->GetListOfLines());
988 while ((o = (TObjString *) nxl())) {
989 if (o->GetString().Index(reds) != kNPOS) {
990 out->Add(o->Clone());
995 if (nf > 0 && gDebug > 0)
996 Info(
"FillLsDataSet",
"no match for dataset uri '/%s/%s/%s'", group, user, dsname);
1001 out->Add(
new TObjString(TString::Format(
"file:%s", lsfile.Data())));
1015 TFileCollection *TDataSetManagerFile::GetDataSet(
const char *group,
1021 TFileCollection *fileList = 0;
1022 Bool_t readshort = (option & kReadShort) ? kTRUE : kFALSE;
1025 TString path, md5path;
1026 if (readshort || !fUseCache ||
1027 (!readshort && fUseCache && (crc = CheckLocalCache(group, user, dsName, option)) <= 0)) {
1028 Bool_t local = (crc == 0) ? kTRUE : kFALSE;
1029 path = GetDataSetPath(group, user, dsName, md5path, local);
1033 Info(
"GetDataSet",
"dataset %s does not exist", path.Data());
1038 TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
1041 if (gSystem->AccessPathName(path, kFileExists)) {
1043 Info(
"GetDataSet",
"file '%s' does not exists", path.Data());
1046 if (gSystem->AccessPathName(path, kReadPermission)) {
1047 Warning(
"GetDataSet",
"file '%s' exists cannot be read (permission denied)", path.Data());
1054 *checksum = TMD5::ReadChecksum(md5path);
1056 Error(
"GetDataSet",
"could not get checksum of %s from %s", path.Data(), md5path.Data());
1061 TFile *f = TFile::Open(path.Data());
1063 Error(
"GetDataSet",
"could not open file %s", path.Data());
1064 if (checksum) SafeDelete(*checksum);
1068 if (option & kReadShort)
1069 fileList =
dynamic_cast<TFileCollection*
> (f->Get(
"dataset_short"));
1072 fileList =
dynamic_cast<TFileCollection*
> (f->Get(
"dataset"));
1085 Int_t TDataSetManagerFile::CheckLocalCache(
const char *group,
const char *user,
1086 const char *dsName, UInt_t option)
1089 static TMacro *uptmac = 0;
1090 Bool_t need_last_update = (option & kNoCacheUpdate) ? kFALSE : kTRUE;
1091 TString locupdtim, locupdate, remupdate;
1092 locupdtim.Form(
"%s/%s.update", fLocalCacheDir.Data(), kDataSet_DataSetList);
1093 locupdate.Form(
"%s/%s", fLocalCacheDir.Data(), kDataSet_DataSetList);
1094 remupdate.Form(
"%s/%s", fDataSetDir.Data(), kDataSet_DataSetList);
1095 need_last_update = (gSystem->AccessPathName(locupdate)) ? kTRUE : need_last_update;
1097 UInt_t tnow = now.Convert();
1098 FileStat_t timst, locst, remst;
1099 if (need_last_update && !gSystem->AccessPathName(locupdtim)) {
1100 if (gSystem->GetPathInfo(locupdtim, timst) == 0) {
1101 need_last_update = kFALSE;
1102 if ((Int_t)tnow > timst.fMtime + fCacheUpdatePeriod) need_last_update = kTRUE;
1105 if (need_last_update) {
1106 if (gSystem->GetPathInfo(remupdate, remst) != 0) {
1107 Error(
"CheckLocalCache",
"cannot get info for remote file '%s' - ignoring", remupdate.Data());
1110 if (gSystem->GetPathInfo(locupdate, locst) == 0) {
1111 need_last_update = kFALSE;
1112 if (remst.fMtime > locst.fMtime) {
1113 need_last_update = kTRUE;
1115 if (!gSystem->AccessPathName(locupdtim))
1116 if (gSystem->Utime(locupdtim, tnow, 0) != 0)
1117 Warning(
"CheckLocalCache",
1118 "cannot set modification time on file '%s' (errno: %d)",
1119 locupdtim.Data(), TSystem::GetErrno());
1124 if (need_last_update) {
1125 if (!TFile::Cp(remupdate, locupdate, kFALSE)) {
1126 Error(
"CheckLocalCache",
"cannot get remote file '%s' - ignoring", remupdate.Data());
1130 if (gSystem->Utime(locupdate, remst.fMtime, 0) != 0) {
1131 Warning(
"CheckLocalCache",
"cannot set modification time on file '%s' (errno: %d)",
1132 locupdate.Data(), TSystem::GetErrno());
1135 if (gSystem->AccessPathName(locupdtim)) {
1136 FILE *ftim = fopen(locupdtim.Data(),
"w");
1138 Warning(
"CheckLocalCache",
"problems create file '%s' (errno: %d)",
1139 locupdtim.Data(), TSystem::GetErrno());
1141 if (fclose(ftim) != 0)
1142 Warning(
"CheckLocalCache",
"problems close file '%s' (errno: %d)",
1143 locupdtim.Data(), TSystem::GetErrno());
1144 if (gSystem->Utime(locupdtim, now.Convert(), 0) != 0)
1145 Warning(
"CheckLocalCache",
1146 "cannot set modification time on file '%s' (errno: %d)",
1147 locupdtim.Data(), TSystem::GetErrno());
1152 uptmac =
new TMacro(locupdate);
1155 if (gSystem->AccessPathName(locupdtim)) {
1156 FILE *ftim = fopen(locupdtim.Data(),
"w");
1158 Warning(
"CheckLocalCache",
"problems create file '%s' (errno: %d)",
1159 locupdtim.Data(), TSystem::GetErrno());
1161 if (fclose(ftim) != 0)
1162 Warning(
"CheckLocalCache",
"problems close file '%s' (errno: %d)",
1163 locupdtim.Data(), TSystem::GetErrno());
1164 if (gSystem->GetPathInfo(locupdate, locst) == 0) {
1165 if (gSystem->Utime(locupdtim, locst.fMtime, 0) != 0)
1166 Warning(
"CheckLocalCache",
1167 "cannot set modification time on file '%s' (errno: %d)",
1168 locupdtim.Data(), TSystem::GetErrno());
1170 Warning(
"CheckLocalCache",
"cannot get info for file '%s'"
1171 " - will not touch '%s'", locupdate.Data(), locupdtim.Data());
1175 if (!uptmac) uptmac =
new TMacro(locupdate);
1179 if (!dsName || strlen(dsName) <= 0)
1183 TString ds, locpath, path, locmd5path, md5path, remmd5s;
1186 path = GetDataSetPath(group, user, dsName, md5path);
1187 locpath = GetDataSetPath(group, user, dsName, locmd5path, kTRUE);
1188 ds.Form(
"/%s/%s/%s", group, user, dsName);
1189 TObjString *os = uptmac->GetLineWith(ds);
1192 if (strcmp(dsName,
"ls"))
1193 Warning(
"CheckLocalCache",
"dataset '%s' does not exists anymore", ds.Data());
1199 while (os->GetString().Tokenize(s, from,
" ")) {
1200 if (!s.IsDigit() && s != ds) {
1204 if (remmd5s ==
"---") {
1206 if (strcmp(dsName,
"ls"))
1207 Warning(
"CheckLocalCache",
"dataset '%s' does not exists anymore", ds.Data());
1210 Bool_t need_update = (option & kNoCacheUpdate) ? kFALSE : kTRUE;
1211 if (!gSystem->AccessPathName(locpath)) {
1213 need_update = kFALSE;
1214 locmd5 = TMD5::ReadChecksum(locmd5path);
1215 if (!locmd5 && !(locmd5 = TMD5::FileChecksum(locpath))) {
1216 Warning(
"CheckLocalCache",
"cannot get checksum of '%s' - assuming match failed", ds.Data());
1217 need_update = kTRUE;
1219 if (remmd5s != locmd5->AsString()) need_update = kTRUE;
1223 need_update = kTRUE;
1228 if (!TFile::Cp(path, locpath, kFALSE)) {
1229 Error(
"CheckLocalCache",
"cannot get remote file '%s' - ignoring", path.Data());
1233 locmd5 = TMD5::FileChecksum(locpath);
1235 if (remmd5s != locmd5->AsString())
1236 Warning(
"CheckLocalCache",
"checksum for freshly downloaded file '%s' does not match the"
1237 " one posted in '%s'", locpath.Data(), kDataSet_DataSetList);
1238 if (TMD5::WriteChecksum(locmd5path, locmd5) != 0)
1239 Warning(
"CheckLocalCache",
"problems saving checksum to '%s' (errno: %d)",
1240 locmd5path.Data(), TSystem::GetErrno());
1242 Warning(
"CheckLocalCache",
"problems calculating checksum for '%s'", locpath.Data());
1253 Int_t TDataSetManagerFile::ClearCache(
const char *uri)
1256 void *dirp = gSystem->OpenDirectory(fLocalCacheDir.Data());
1258 Error(
"ClearCache",
"cannot open directory '%s' (errno: %d)",
1259 fLocalCacheDir.Data(), TSystem::GetErrno());
1263 if (uri && strlen(uri) > 0) {
1264 if (strcmp(uri,
"*") && strcmp(uri,
"/*") && strcmp(uri,
"/*/") &&
1265 strcmp(uri,
"/*/*") && strcmp(uri,
"/*/*/") && strcmp(uri,
"/*/*/*")) {
1268 if (u(0) ==
'/') u.Remove(0,1);
1270 u.ReplaceAll(
"/",
".");
1272 u.ReplaceAll(
"*",
".*");
1273 re =
new TRegexp(u.Data());
1277 Printf(
" Dataset repository: %s", fDataSetDir.Data());
1278 Printf(
" Local cache directory: %s", fLocalCacheDir.Data());
1280 Long64_t totsz = 0, nf = 0;
1284 while ((e = gSystem->GetDirEntry(dirp))) {
1286 if (!strcmp(e,
".") || !strcmp(e,
".."))
continue;
1288 if (re && TString(e).Index(*re) == kNPOS)
continue;
1290 path.Form(
"%s/%s", fLocalCacheDir.Data(), e);
1292 if (gSystem->GetPathInfo(path, st) != 0) {
1293 Warning(
"ShowCache",
"problems 'stat'-ing '%s' (errno: %d)",
1294 path.Data(), TSystem::GetErrno());
1301 if (gSystem->Unlink(path) != 0) {
1302 Warning(
"ClearCache",
"problems unlinking '%s' (errno: %d)",
1303 path.Data(), TSystem::GetErrno());
1306 gSystem->FreeDirectory(dirp);
1310 Printf(
" %lld bytes (%lld files) have been freed", totsz, nf);
1319 Int_t TDataSetManagerFile::ShowCache(
const char *uri)
1322 void *dirp = gSystem->OpenDirectory(fLocalCacheDir.Data());
1324 Error(
"ShowCache",
"cannot open directory '%s' (errno: %d)",
1325 fLocalCacheDir.Data(), TSystem::GetErrno());
1329 if (uri && strlen(uri) > 0) {
1330 if (strcmp(uri,
"*") && strcmp(uri,
"/*") && strcmp(uri,
"/*/") &&
1331 strcmp(uri,
"/*/*") && strcmp(uri,
"/*/*/") && strcmp(uri,
"/*/*/*")) {
1334 if (u(0) ==
'/') u.Remove(0,1);
1336 u.ReplaceAll(
"/",
".");
1338 u.ReplaceAll(
"*",
".*");
1339 re =
new TRegexp(u.Data());
1343 Printf(
" Dataset repository: %s", fDataSetDir.Data());
1344 Printf(
" Local cache directory: %s", fLocalCacheDir.Data());
1345 Printf(
" Last modified Size(bytes) File");
1347 Long64_t totsz = 0, nf = 0;
1351 while ((e = gSystem->GetDirEntry(dirp))) {
1353 if (!strcmp(e,
".") || !strcmp(e,
".."))
continue;
1355 if (re && TString(e).Index(*re) == kNPOS)
continue;
1357 path.Form(
"%s/%s", fLocalCacheDir.Data(), e);
1359 if (gSystem->GetPathInfo(path, st) != 0) {
1360 Warning(
"ShowCache",
"problems 'stat'-ing '%s' (errno: %d)",
1361 path.Data(), TSystem::GetErrno());
1368 TDatime tmod(st.fMtime);
1369 sz.Form(
"%lld", st.fSize);
1371 Printf(
" %s %s %s", tmod.AsSQLString(), sz.Data(), e);
1373 gSystem->FreeDirectory(dirp);
1377 Printf(
" %lld files, %lld bytes", nf, totsz);
1394 Int_t TDataSetManagerFile::WriteDataSet(
const char *group,
const char *user,
1395 const char *dsName, TFileCollection *dataset,
1396 UInt_t option, TMD5 *checksum)
1398 TString md5path, path, md5sum;
1400 { TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
1402 Bool_t checkIfExists = ((option & kFileMustExist) || checksum) ? kTRUE : kFALSE;
1404 path = GetDataSetPath(group, user, dsName, md5path);
1406 if (checkIfExists) {
1409 if (gSystem->GetPathInfo(path, 0, (Long_t*) 0, 0, &tmp) != 0) {
1411 Info(
"WriteDataSet",
"Dataset disappeared. Discarding update.");
1418 TMD5 *checksum2 = TMD5::FileChecksum(path);
1420 Error(
"WriteDataSet",
"Could not get checksum of %s", path.Data());
1424 Bool_t checksumAgrees = (*checksum == *checksum2);
1427 if (!checksumAgrees) {
1429 Info(
"WriteDataSet",
"Dataset changed. Discarding update.");
1435 TString tempFile(path);
1437 while (tempFile.Index(
"/", index+1) >= 0)
1438 index = tempFile.Index(
"/", index+1);
1440 tempFile.Insert(index+1,
".");
1442 TFile *f = TFile::Open(tempFile,
"RECREATE");
1444 Error(
"WriteDataSet",
"Could not open dataset for writing %s", tempFile.Data());
1449 dataset->Write(
"dataset", TObject::kSingleKey | TObject::kOverwrite);
1452 THashList *list = dataset->GetList();
1453 dataset->SetList(0);
1454 dataset->Write(
"dataset_short", TObject::kSingleKey | TObject::kOverwrite);
1460 dataset->SetList(list);
1463 if (gSystem->Rename(tempFile, path) != 0) {
1464 Error(
"WriteDataSet",
"renaming %s to %s failed; dataset might be corrupted",
1465 tempFile.Data(), path.Data());
1467 if (!gSystem->AccessPathName(md5path, kWritePermission) && gSystem->Unlink(md5path) != 0)
1468 Error(
"WriteDataSet",
"unlink of %s failed", md5path.Data());
1471 else if (fOpenPerms) {
1472 if (gSystem->Chmod(path.Data(), 0666) < 0) {
1473 Warning(
"NotifyUpdate",
1474 "can't set permissions of dataset file %s (#%d)",
1475 path.Data(), TSystem::GetErrno());
1480 if (ChecksumDataSet(path, md5path, md5sum) != 0) {
1481 Error(
"WriteDataSet",
"problems calculating checksum of %s", path.Data());
1484 else if (fOpenPerms) {
1485 if (gSystem->Chmod(md5path.Data(), 0666) < 0) {
1486 Warning(
"NotifyUpdate",
1487 "can't set permissions of dataset MD5 checksum file %s (#%d)",
1488 md5path.Data(), TSystem::GetErrno());
1493 if (gSystem->GetPathInfo(path, st) != 0) {
1494 Error(
"WriteDataSet",
"could not 'stat' the version of '%s'!", path.Data());
1501 if (NotifyUpdate(group, user, dsName, mtime, md5sum) != 0)
1502 Warning(
"WriteDataSet",
"problems notifying update with 'NotifyUpdate'");
1512 Int_t TDataSetManagerFile::ChecksumDataSet(
const char *path,
1513 const char *md5path, TString &checksum)
1517 if (!path || strlen(path) <= 0 || !md5path || strlen(md5path) <= 0) {
1518 Error(
"ChecksumDataSet",
"one or more inputs are invalid ('%s','%s')",
1523 TMD5 *md5sum = TMD5::FileChecksum(path);
1525 Error(
"ChecksumDataSet",
"problems calculating checksum of '%s'", path);
1529 if (TMD5::WriteChecksum(md5path, md5sum) != 0) {
1530 Error(
"ChecksumDataSet",
"problems saving checksum to '%s'", md5path);
1535 checksum = md5sum->AsString();
1544 Bool_t TDataSetManagerFile::RemoveDataSet(
const char *group,
const char *user,
1547 TString md5path, path;
1548 { TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
1550 path = GetDataSetPath(group, user, dsName, md5path);
1553 if ((rc = gSystem->Unlink(path)) != 0)
1554 Warning(
"RemoveDataSet",
"problems removing main file '%s' (errno: %d)",
1555 path.Data(), TSystem::GetErrno());
1557 if (gSystem->Unlink(md5path) != 0)
1558 Warning(
"RemoveDataSet",
"problems removing chcksum file '%s' (errno: %d)",
1559 md5path.Data(), TSystem::GetErrno());
1563 if (gSystem->AccessPathName(path, kFileExists)) {
1564 if (NotifyUpdate(group, user, dsName, 0,
"removed") != 0)
1565 Warning(
"RemoveDataSet",
"problems notifying update with 'NotifyUpdate'");
1576 Bool_t TDataSetManagerFile::ExistsDataSet(
const char *group,
const char *user,
1579 TLockFile lock(fDataSetLockFile, fLockFileTimeLimit);
1581 TString md5path, path(GetDataSetPath(group, user, dsName, md5path));
1583 return (gSystem->AccessPathName(path) == kFALSE);
1598 Int_t TDataSetManagerFile::RegisterDataSet(
const char *uri,
1599 TFileCollection *newDataSet,
1602 if (!TestBit(TDataSetManager::kAllowRegister))
1607 if (ParseUri(uri, 0, 0, &dsName, 0, kTRUE) == kFALSE) {
1608 Error(
"RegisterDataSet",
"problem parsing uri: %s", uri);
1613 TFileCollection *dataSet = newDataSet;
1617 if (opt.Contains(
"U", TString::kIgnoreCase)) {
1619 if (ExistsDataSet(fGroup, fUser, dsName)) {
1621 if (!(dataSet = GetDataSet(fGroup, fUser, dsName))) {
1623 Warning(
"RegisterDataSet",
1624 "dataset '%s' claimed to exists but retrieval failed - ignoring", uri);
1625 dataSet = newDataSet;
1628 dataSet->Add(newDataSet);
1631 }
else if (!opt.Contains(
"O", TString::kIgnoreCase)) {
1633 if (ExistsDataSet(fGroup, fUser, dsName)) {
1635 Error(
"RegisterDataSet",
"dataset '%s' exists already", uri);
1641 TList *uniqueFileList =
new TList();
1642 TIter nextFile(dataSet->GetList());
1643 TFileInfo *prevFile = (TFileInfo*)nextFile();
1644 uniqueFileList->Add(prevFile);
1645 while (TFileInfo *obj = (TFileInfo*)nextFile()) {
1647 if (!uniqueFileList->FindObject(obj->GetFirstUrl()->GetUrl()))
1648 uniqueFileList->Add(obj);
1653 dataSet->GetList()->SetOwner(0);
1654 dataSet->GetList()->Clear(
"nodelete");
1655 dataSet->GetList()->SetOwner(1);
1656 dataSet->GetList()->AddAll(uniqueFileList);
1657 uniqueFileList->SetOwner(kFALSE);
1658 delete uniqueFileList;
1661 Bool_t reset = kTRUE;
1662 if (opt.Contains(
"T", TString::kIgnoreCase)) {
1663 if (!TestBit(TDataSetManager::kTrustInfo)) {
1664 Warning(
"RegisterDataSet",
"configured to not trust the information"
1665 " provided by users: ignoring request");
1671 dataSet->SetName(dsName);
1672 dataSet->ResetBitAll(TFileInfo::kStaged);
1673 dataSet->ResetBitAll(TFileInfo::kCorrupted);
1674 dataSet->RemoveMetaData();
1678 if (opt.Contains(
"V", TString::kIgnoreCase)) {
1679 if (TestBit(TDataSetManager::kAllowVerify)) {
1681 if (TDataSetManager::ScanDataSet(dataSet, 1, 0, 0, kTRUE ) < 0) {
1682 Error(
"RegisterDataSet",
"problems verifying the dataset");
1686 Warning(
"RegisterDataSet",
"user-driven verification not allowed: ignoring request");
1691 dataSet->Update(fAvgFileSize);
1693 if (TestBit(TDataSetManager::kCheckQuota)) {
1694 if (dataSet->GetTotalSize() <= 0) {
1695 Error(
"RegisterDataSet",
"datasets without size information are not accepted:");
1696 if (fAvgFileSize < 0) {
1697 Error(
"RegisterDataSet",
"you may want to define an average"
1698 " file size to get an estimated dataset size");
1704 Long64_t used = GetGroupUsed(fGroup) + dataSet->GetTotalSize();
1706 Info(
"RegisterDataSet",
"your group %s uses %.1f GB + %.1f GB for the new dataset; "
1707 "the available quota is %.1f GB", fGroup.Data(),
1708 (Float_t) GetGroupUsed(fGroup) / 1073741824,
1709 (Float_t) dataSet->GetTotalSize() / 1073741824,
1710 (Float_t) GetGroupQuota(fGroup) / 1073741824);
1711 if (used > GetGroupQuota(fGroup)) {
1712 Error(
"RegisterDataSet",
"quota exceeded");
1717 Bool_t success = WriteDataSet(fGroup, fUser, dsName, dataSet);
1719 Error(
"RegisterDataSet",
"could not write dataset: %s", dsName.Data());
1722 return ((success) ? 0 : -1);
1730 Int_t TDataSetManagerFile::ScanDataSet(
const char *uri, UInt_t opt)
1732 TString dsName, dsTree;
1733 if ((opt & kSetDefaultTree)) {
1734 if (TestBit(TDataSetManager::kAllowRegister)) {
1735 if (ParseUri(uri, 0, 0, &dsName, &dsTree, kTRUE)) {
1736 TFileCollection *dataset = GetDataSet(fGroup, fUser, dsName);
1737 if (!dataset)
return -1;
1738 dataset->SetDefaultTreeName(dsTree.Data());
1739 Int_t rc = WriteDataSet(fGroup, fUser, dsName, dataset);
1741 return (rc == 0) ? -1 : 0;
1745 if (TestBit(TDataSetManager::kAllowVerify)) {
1746 if (ParseUri(uri, 0, 0, &dsName, 0, kTRUE, kTRUE)) {
1747 if (!(dsName.Contains(
"*"))) {
1748 if (ScanDataSet(fGroup, fUser, dsName, opt) > 0)
1749 return GetNDisapparedFiles();
1751 TString luri = TString::Format(
"/%s/%s/%s", fGroup.Data(), fUser.Data(), dsName.Data());
1752 TMap *fcs = GetDataSets(luri, kList);
1753 if (!fcs)
return -1;
1755 Int_t ndisappeared = 0;
1758 while ((d = (TObjString *) nxd())) {
1759 if (!(d->GetString().IsNull())) {
1760 TString dsn(d->GetName());
1761 if (dsn.Contains(
"/")) dsn.Remove(0, dsn.Last(
'/') + 1);
1762 if (ScanDataSet(fGroup, fUser, dsn, opt) > 0) {
1763 ndisappeared += GetNDisapparedFiles();
1765 Warning(
"ScanDataSet",
"problems processing dataset: %s", d->GetName());
1768 Warning(
"ScanDataSet",
"empty string found in map while processing: %s", uri);
1772 return ndisappeared;
1783 Int_t TDataSetManagerFile::ScanDataSet(
const char *group,
const char *user,
1784 const char *dsName, UInt_t option)
1786 if (!TestBit(TDataSetManager::kAllowVerify))
1789 TFileCollection *dataset = GetDataSet(group, user, dsName);
1794 Int_t fopt = ((option & kAllFiles)) ? -1 : 0;
1796 if ((option & kStagedFiles)) {
1799 if ((option & kReopen)) fopt++;
1800 if ((option & kTouch)) fopt++;
1802 if ((option & kNoStagedCheck)) fopt += 100;
1804 if ((option & kStagedFiles) || (option & kReopen) || (option & kTouch)) {
1805 Warning(
"ScanDataSet",
"kAllFiles mode: ignoring kStagedFiles or kReopen"
1806 " or kTouch requests");
1808 if ((option & kNoStagedCheck)) fopt -= 100;
1812 Int_t sopt = ((option & kNoAction)) ? -1 : 0;
1814 if ((option & kLocateOnly) && (option & kStageOnly)) {
1815 Error(
"ScanDataSet",
"kLocateOnly and kStageOnly cannot be processed concurrently");
1818 if ((option & kLocateOnly)) sopt = 1;
1819 if ((option & kStageOnly)) sopt = 2;
1820 }
else if ((option & kLocateOnly) || (option & kStageOnly)) {
1821 Warning(
"ScanDataSet",
"kNoAction mode: ignoring kLocateOnly or kStageOnly requests");
1824 Bool_t dbg = ((option & kDebug)) ? kTRUE : kFALSE;
1826 Int_t result = TDataSetManager::ScanDataSet(dataset, fopt, sopt, 0, dbg,
1827 &fNTouchedFiles, &fNOpenedFiles, &fNDisappearedFiles,
1828 (TList *)0, fAvgFileSize, fMSSUrl.Data(), -1, fStageOpts.Data());
1830 if (WriteDataSet(group, user, dsName, dataset) == 0) {
1859 TMap *TDataSetManagerFile::GetDataSets(
const char *uri, UInt_t option)
1861 TString dsUser, dsGroup, dsName;
1863 if (((option & kPrint) || (option & kExport)) && strlen(uri) <= 0)
1864 option |= kShowDefault;
1866 if (ParseUri(uri, &dsGroup, &dsUser, &dsName, 0, kFALSE, kTRUE))
1867 return GetDataSets(dsGroup, dsUser, dsName, option);
1874 TFileCollection *TDataSetManagerFile::GetDataSet(
const char *uri,
const char *opts)
1876 TString dsUser, dsGroup, dsName, ss(opts);
1878 TFileCollection *fc = 0;
1879 if (!strchr(uri,
'*')) {
1880 if (!ParseUri(uri, &dsGroup, &dsUser, &dsName))
return fc;
1881 UInt_t opt = (ss.Contains(
"S:") || ss.Contains(
"short:")) ? kReadShort : 0;
1882 ss.ReplaceAll(
"S:",
"");
1883 ss.ReplaceAll(
"short:",
"");
1884 fc = GetDataSet(dsGroup, dsUser, dsName, opt);
1886 TMap *fcs = GetDataSets(uri);
1887 if (!fcs)
return fc;
1890 TFileCollection *xfc = 0;
1891 while ((k = nxd()) && (xfc = (TFileCollection *) fcs->GetValue(k))) {
1903 if (fc && !ss.IsNull()) {
1905 TFileCollection *sfc = 0;
1908 while (ss.Tokenize(s, from,
",")) {
1909 TFileCollection *xfc = fc->GetFilesOnServer(s.Data());
1930 Bool_t TDataSetManagerFile::RemoveDataSet(
const char *uri)
1934 if (TestBit(TDataSetManager::kAllowRegister)) {
1935 if (ParseUri(uri, 0, 0, &dsName, 0, kTRUE)) {
1936 Bool_t rc = RemoveDataSet(fGroup, fUser, dsName);
1937 if (rc)
return kTRUE;
1938 Error(
"RemoveDataSet",
"error removing dataset %s", dsName.Data());
1947 Bool_t TDataSetManagerFile::ExistsDataSet(
const char *uri)
1949 TString dsUser, dsGroup, dsName;
1951 if (ParseUri(uri, &dsGroup, &dsUser, &dsName))
1952 return ExistsDataSet(dsGroup, dsUser, dsName);
1959 void TDataSetManagerFile::UpdateUsedSpace()
1962 fGroupUsed.DeleteAll();
1963 fUserUsed.DeleteAll();
1966 GetDataSets(0, 0, 0, (UInt_t)kQuotaUpdate);
1973 Long_t TDataSetManagerFile::GetModTime(
const char *uri)
1975 TString group, user, name, md5path;
1976 if (!ParseUri(uri, &group, &user, &name)) {
1980 TString path( GetDataSetPath(group, user, name, md5path) );
1983 if (gSystem->GetPathInfo(path.Data(),
1984 (Long_t *)0, (Long_t *)0, (Long_t *)0, &modTime)) {