Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPackMgr.cxx
Go to the documentation of this file.
1// @(#)root/proof:$Id$
2// Author: G. Ganis, Oct 2015
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TPackMgr
13\ingroup proofkernel
14
15The PROOF package manager contains tools to manage packages.
16This class has been created to eliminate duplications, and to allow for
17standalone usage.
18
19*/
20
21#include "TPackMgr.h"
22
23#include "TError.h"
24#include "TFile.h"
25#include "TFunction.h"
26#include "THashList.h"
27#include "TList.h"
28#include "TMacro.h"
29#include "TMD5.h"
30#include "TMethodArg.h"
31#include "TMethodCall.h"
32#include "TObjString.h"
33#include "TParameter.h"
34#include "TMap.h"
35#include "TProof.h" // for constants such as kRM and kLS.
36#include "TROOT.h"
37#include "TSystem.h"
38
40
41
42static void DefaultLogger(const char *msg) { Printf("%s", msg); }
43
44THashList *TPackMgr::fgGlobalPackMgrList = 0; // list of package managers for global packages
45
46////////////////////////////////////////////////////////////////////////////////
47/// Create a PROOF package manager
48
49TPackMgr::TPackMgr(const char *dir, const char *key)
50 : fLogger(DefaultLogger), fName(key), fDir(dir), fLock(dir), fEnabledPackages(0)
51{
52 // Work with full names
54 Warning("TPackMgr", "problems expanding path '%s'", fDir.Data());
55 // The lock file in temp
56 TString lockname = TString::Format("%s/packdir-lock-%s",
57 gSystem->TempDirectory(), TString(fDir).ReplaceAll("/","%").Data());
58 fLock.SetName(lockname);
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Destroy a TPackMgr instance
63
65{
66 // Destroy the lock file
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Wrapper to notofuer / logger
72
73void TPackMgr::Log(const char *msg)
74{
75 if (fLogger) {
76 if (fPfx.IsNull())
77 (*fLogger)(msg);
78 else
79 (*fLogger)(TString::Format("%s: %s", fPfx.Data(), msg));
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Method to build a package.
85/// Return -1 on error, 0 otherwise
86
87Int_t TPackMgr::Build(const char *pack, Int_t opt)
88{
89 Int_t rc = 0;
90
92
93 if (gDebug > 0)
94 Info("Build", "building package %s ...", pack);
95
97 TString pdir = TString::Format("%s/%s", fDir.Data(), pack);
99
100 // check for BUILD.sh and execute
101 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
102 // Notify the upper level
103 Log(TString::Format("building %s ...", pack));
104
105 // Read version from file proofvers.txt, and if current version is
106 // not the same do a "BUILD.sh clean"
107 Bool_t goodver = kTRUE;
108 Bool_t savever = kFALSE;
109 TString v, r;
110 FILE *f = fopen("PROOF-INF/proofvers.txt", "r");
111 if (f) {
112 v.Gets(f);
113 r.Gets(f);
114 fclose(f);
115 if (opt == TPackMgr::kCheckROOT && v != gROOT->GetVersion()) goodver = kFALSE;
116 }
117 if (!f || !goodver) {
119 savever = kTRUE;
120 Log(TString::Format("%s: version change"
121 " (current: %s, build: %s): cleaning ... ",
122 pack, gROOT->GetVersion(), v.Data()));
123 // Hard cleanup: go up the dir tree
125 // remove package directory
126 gSystem->Exec(TString::Format("%s %s", kRM, pdir.Data()));
127 // find gunzip...
128 char *gunzip = gSystem->Which(gSystem->Getenv("PATH"), kGUNZIP,
130 if (gunzip) {
131 TString par;
132 par.Form("%s.par", pdir.Data());
133 // untar package
134 TString cmd;
135 cmd.Form(kUNTAR3, gunzip, par.Data());
136 rc = gSystem->Exec(cmd);
137 if (rc != 0) {
138 Error("Build", "failure executing: %s", cmd.Data());
139 } else {
140 // Store md5 in package/PROOF-INF/md5.txt
141 TMD5 *md5local = TMD5::FileChecksum(par);
142 if (md5local) {
143 TString md5f = pdir + "/PROOF-INF/md5.txt";
144 TMD5::WriteChecksum(md5f, md5local);
145 // Go down to the package directory
147 // Cleanup
148 SafeDelete(md5local);
149 } else {
150 Warning("Build", "failure calculating/saving MD5sum for '%s'", par.Data());
151 }
152 }
153 delete [] gunzip;
154 } else {
155 Error("Build", "%s not found", kGUNZIP);
156 rc = -1;
157 }
158 } else {
159 Log(TString::Format("%s: ROOT version inconsistency (current: %s, build: %s):"
160 " directory not writable: cannot re-build!!! ",
161 pack, gROOT->GetVersion(), v.Data()));
162 rc = -1;
163 }
164
165 if (rc == 0) {
166 // To build the package we execute PROOF-INF/BUILD.sh via a pipe
167 // so that we can send back the log in (almost) real-time to the
168 // (impatient) client. Note that this operation will block, so
169 // the messages from builds on the workers will reach the client
170 // shortly after the master ones.
172 ipath.ReplaceAll("\"","");
173 TString cmd;
174 cmd.Form("export ROOTINCLUDEPATH=\"%s\" ; PROOF-INF/BUILD.sh", ipath.Data());
175 rc = gSystem->Exec(cmd);
176 if (rc != 0) {
177 Error("Build", "failure executing: %s", cmd.Data());
178 } else {
179 // Success: write version file
180 if (savever) {
181 f = fopen("PROOF-INF/proofvers.txt", "w");
182 if (f) {
183 fputs(gROOT->GetVersion(), f);
184 fputs(TString::Format("\n%s", gROOT->GetGitCommit()), f);
185 fclose(f);
186 }
187 }
188 }
189 }
190 } else {
191 // Notify the user
192 if (gDebug > 0)
193 Info("Build", "no PROOF-INF/BUILD.sh found for package %s", pack);
194 }
195 }
196 // Always return to the initial directory
198
199 return rc;
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Method to load a package taking an option const char *
204/// Return -1 on error, 0 otherwise
205
206Int_t TPackMgr::Load(const char *pack, const char *opts)
207{
208 TList *optls = new TList;
209 optls->Add(new TObjString(opts));
210 Int_t rc = Load(pack, optls);
211 optls->SetOwner();
212 delete optls;
213 return rc;
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Method to load a package taking an option list
218/// Return -1 on error, 0 otherwise
219
220Int_t TPackMgr::Load(const char *pack, TList *optls)
221{
222 Int_t rc = 0;
223 TString emsg;
224
225 // If already loaded don't do it again
227 Log(TString::Format("error: TPackMgr::Load: package %s already loaded", pack));
228 return 0;
229 }
230
231 // Which pack mgr has the package?
232 if (!Has(pack)) {
233 // Check the global packages
234 TPackMgr *packmgr = 0;
235 if (!(packmgr = TPackMgr::GetPackMgr(pack, nullptr))) {
236 // Package not found
237 Log(TString::Format("error: TPackMgr::Load: failure locating %s ...", pack));
238 return -1;
239 }
240 // Load from there
241 return packmgr->Load(pack, optls);
242 }
243
244 // We have the package
245 TString pdir = TString::Format("%s/%s", fDir.Data(), pack);
246
247 // Check dependencies
248 TString deps = TString::Format("%s/PROOF-INF/depends", pdir.Data());
249 if (!gSystem->AccessPathName(deps)) {
250 TMacro mdeps("deps");
251 if (mdeps.ReadFile(deps) > 0) {
252 Log(TString::Format("info: TPackMgr::Load: checking dependencies for package %s ...", pack));
253 TIter nxl(mdeps.GetListOfLines());
254 TObjString *os = 0;
255 while ((os = (TObjString *)nxl())) {
256 if (!TPackMgr::IsEnabled(os->GetName(), this)) {
257 if (Load(os->GetName(), optls) < 0) {
258 // Package loading failure
259 Log(TString::Format("error: TPackMgr::Load: failure loading dep %s ...", os->GetName()));
260 return -1;
261 }
262 }
263 }
264 }
265 }
266
267 // Make sure it has been build
268 Int_t chkveropt = kCheckROOT;
269 if (optls) {
270 TParameter<Int_t> *pcv = (TParameter<Int_t> *) optls->FindObject("PROOF_Package_CheckVersion");
271 if (pcv) {
272 chkveropt = pcv->GetVal();
273 optls->Remove(pcv);
274 delete pcv;
275 }
276 }
277 if (Build(pack, chkveropt) < 0) {
278 // Package not found
279 Log(TString::Format("error: TPackMgr::Load: package %s oes not build! ", pack));
280 return -1;
281 }
282
285
286 // Shared lock from here
288
289 // Check for SETUP.C and execute
290 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
291 // We need to change the name of the function to avoid problems when we load more packages
292 TString setup;
293 setup.Form("SETUP_%d_%x", gSystem->GetPid(), TString(pack).Hash());
294 // Remove special characters
295 TMacro setupmc("PROOF-INF/SETUP.C");
296 TObjString *setupline = setupmc.GetLineWith("SETUP(");
297 if (setupline) {
298 TString setupstring(setupline->GetString());
299 setupstring.ReplaceAll("SETUP(", TString::Format("%s(", setup.Data()));
300 setupline->SetString(setupstring);
301 } else {
302 // Macro does not contain SETUP()
303 Log(TString::Format("warning: macro '%s/PROOF-INF/SETUP.C' does not contain a SETUP()"
304 " function", pack));
305 }
306
307 // Load the macro
308 if (!setupmc.Load()) {
309 // Macro could not be loaded
310 Log(TString::Format("error: macro '%s/PROOF-INF/SETUP.C' could not be loaded:"
311 " cannot continue", pack));
312 rc = -1;
313 } else {
314 // Check the signature
315 TFunction *fun = (TFunction *) gROOT->GetListOfGlobalFunctions()->FindObject(setup);
316 if (!fun) {
317 // Notify the upper level
318 Log(TString::Format("error: function SETUP() not found in macro '%s/PROOF-INF/SETUP.C':"
319 " cannot continue", pack));
320 rc = -1;
321 } else {
322 TMethodCall callEnv;
323 // Check the number of arguments
324 if (fun->GetNargs() == 0) {
325 // No arguments (basic signature)
326 callEnv.Init(fun);
327 if (optls && optls->GetSize() > 0) {
328 Log(TString::Format("warning: loaded SETUP() for '%s' does not take any argument:"
329 " the specified argument will be ignored", pack));
330 }
331 } else if (fun->GetNargs() == 1) {
332 TMethodArg *arg = (TMethodArg *) fun->GetListOfMethodArgs()->First();
333 if (arg) {
334 callEnv.Init(fun);
335 // Check argument type
336 TString argsig(arg->GetTitle());
337 if (argsig.BeginsWith("TList")) {
338 callEnv.ResetParam();
339 callEnv.SetParam((Longptr_t) optls);
340 } else if (argsig.BeginsWith("const char")) {
341 callEnv.ResetParam();
342 TObjString *os = optls ? dynamic_cast<TObjString *>(optls->First()) : 0;
343 if (os) {
344 callEnv.SetParam((Longptr_t) os->GetName());
345 } else {
346 if (optls && optls->First()) {
347 Log(TString::Format("warning: found object argument of type %s:"
348 " SETUP expects 'const char *': ignoring",
349 optls->First()->ClassName()));
350 }
351 callEnv.SetParam((Long_t) 0);
352 }
353 } else {
354 // Notify the upper level
355 Log(TString::Format("error: unsupported SETUP signature: SETUP(%s)"
356 " cannot continue", arg->GetTitle()));
357 rc = -1;
358 }
359 } else {
360 // Notify the upper level
361 Log("error: cannot get information about the SETUP() argument:"
362 " cannot continue");
363 rc = -1;
364 }
365 } else if (fun->GetNargs() > 1) {
366 // Notify the upper level
367 Log("error: function SETUP() can have at most a 'TList *' argument:"
368 " cannot continue");
369 rc = -1;
370 }
371 // Execute
372 Longptr_t setuprc = (rc == 0) ? 0 : -1;
373 if (rc == 0) {
374 callEnv.Execute(setuprc);
375 if (setuprc < 0) rc = -1;
376 }
377 }
378 }
379 }
380
382
383 if (rc == 0) {
384 // create link to package in working directory
385 gSystem->Symlink(pdir, pack);
386
387 // add package to list of include directories to be searched
388 // by ACliC
389 gSystem->AddIncludePath(TString::Format("-I%s", pack));
390
391 // add package to list of include directories to be searched by CINT
392 gROOT->ProcessLine(TString::Format(".I %s", pack));
393
394 TPair *pck = (optls && optls->GetSize() > 0) ? new TPair(new TObjString(pack), optls->Clone())
395 : new TPair(new TObjString(pack), 0);
396 if (!fEnabledPackages) {
399 }
400 fEnabledPackages->Add(pck);
401 }
402
403 return rc;
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Method to unload a package.
409/// Return -1 on error, 0 otherwise
410
411Int_t TPackMgr::Unload(const char *pack)
412{
413 Int_t rc = 0;
414
416 TPair *ppack = 0;
417 if (pack && strlen(pack) > 0) {
418 if ((ppack = (TPair *) fEnabledPackages->FindObject(pack))) {
419
420 // Remove entry from include path
421 TString aclicincpath = gSystem->GetIncludePath();
422 TString cintincpath = gInterpreter->GetIncludePath();
423 // remove interpreter part of gSystem->GetIncludePath()
424 aclicincpath.Remove(aclicincpath.Length() - cintincpath.Length() - 1);
425 // remove package's include path
426 aclicincpath.ReplaceAll(TString(" -I") + pack, "");
427 gSystem->SetIncludePath(aclicincpath);
428
429 //TODO reset interpreter include path
430
431 // remove entry from enabled packages list
432 delete fEnabledPackages->Remove(ppack);
433 }
434
435 // Cleanup the link, if there
436 if (!gSystem->AccessPathName(pack))
437 if (gSystem->Unlink(pack) != 0) rc = -1;
438
439 } else {
440
441 // Iterate over packages and remove each package
443 while ((ppack = (TPair *) nxp())) {
444 if (Unload(ppack->GetName()) != 0) rc = -1;
445 }
446
447 }
448 }
449
450 // We are done
451 return rc;
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Method to check if this package manager has package 'pack'.
456/// Return kTRUE or kFALSE
457
458Bool_t TPackMgr::Has(const char *pack)
459{
460 // always follows BuildPackage so no need to check for PROOF-INF
461 TString pdir = TString::Format("%s/%s", fDir.Data(), pack);
462
463 // Shared lock from here
465
467 gSystem->AccessPathName(pdir + "/PROOF-INF", kReadPermission))
468 return kFALSE;
469
470 // Relevant directories exist and ar readable
471 return kTRUE;
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Method to check if 'path' is in the managed directory
476/// Return kTRUE or kFALSE
477
478Bool_t TPackMgr::IsInDir(const char *path)
479{
480 return strncmp(fDir.Data(), path, fDir.Length()) ? kFALSE : kTRUE ;
481}
482
483////////////////////////////////////////////////////////////////////////////////
484/// Method to get the path of the dir for package 'pack'.
485/// Return -1 in case of error (not found), 0 otherwise
486
487Int_t TPackMgr::GetPackDir(const char *pack, TString &pdir)
488{
489 // Make sure the extension is not ".par"
490 TString pn(pack);
491 if (strstr(pack, ".par")) pn.Remove(pn.Last('.'));
492 pdir.Form("%s/%s", fDir.Data(), pn.Data());
493 if (gSystem->AccessPathName(pdir, kReadPermission)) return -1;
494 return 0;
495}
496
497////////////////////////////////////////////////////////////////////////////////
498/// Method to get a semi-colon separated list with the names of the enabled
499/// packages.
500
502{
503 packlist = "";
504 if (!fEnabledPackages) return;
505
507 TPair *pck= 0;
508 while ((pck = (TPair *)nxp())) {
509 if (packlist.Length() <= 0)
510 packlist = pck->GetName();
511 else
512 packlist += TString::Format(";%s", pck->GetName());
513 }
514 return;
515}
516
517////////////////////////////////////////////////////////////////////////////////
518/// Method to get the path of the PAR file for package 'pack'.
519/// Return -1 in case of error (not found), 0 otherwise
520
521Int_t TPackMgr::GetParPath(const char *pack, TString &path)
522{
523 // Make sure the extension is ".par"
524 const char *fm = (strstr(pack, ".par")) ? "%s/%s" : "%s/%s.par";
525 path.Form(fm, fDir.Data(), pack);
526 if (gSystem->AccessPathName(path, kReadPermission)) return -1;
527 return 0;
528}
529
530////////////////////////////////////////////////////////////////////////////////
531/// Method to get the download dir; create if not existing
532/// Return -1 in case of error (not found; not created), 0 otherwise
533
535{
536 dldir.Form("%s/downloaded", fDir.Data());
538 if (gSystem->mkdir(dldir, kTRUE) != 0) return -1;
539 if (gSystem->AccessPathName(dldir, kReadPermission)) return -1;
540 }
541 return 0;
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// Show available packages
546///
547
548void TPackMgr::Show(const char *title)
549{
551 // Scan the list of global packages dirs
553 TPackMgr *pm = 0;
554 while ((pm = (TPackMgr *)nxpm())) {
555 pm->Show(TString::Format("*** Global Package cache %s %s:%s ***\n",
556 pm->GetName(), gSystem->HostName(), pm->GetTitle()));
557 }
558 }
559
560 if (title && strlen(title) > 0)
561 printf("%s\n", title);
562 else
563 printf("*** Package cache %s:%s ***\n", gSystem->HostName(), fDir.Data());
564 fflush(stdout);
565 // Shared lock from here
567 gSystem->Exec(TString::Format("%s %s", kLS, fDir.Data()));
568 printf("\n");
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Clean dir for package 'pack'
573/// Return -1 in case of error, 0 otherwise
574///
575
576Int_t TPackMgr::Clean(const char *pack)
577{
578 // Shared lock from here
580 Int_t rc = 0;
581 if (pack && strlen(pack)) {
582 // remove package directory and par file
583 rc = gSystem->Exec(TString::Format("%s %s/%s/*", kRM, fDir.Data(), pack));
584 }
585 return rc;
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Remove package 'pack'
590/// If 'pack' is null or empty all packages are cleared
591///
592
593Int_t TPackMgr::Remove(const char *pack, Bool_t dolock)
594{
595 // Shared lock from here
596 if (dolock) fLock.Lock();
597 Int_t rc1 = 0, rc2 = 0, rc3 = 0;
598 if (pack && strlen(pack)) {
599 // remove package directory and par file
600 TString path = TString::Format("%s/downloaded/%s.par", fDir.Data(), pack);
601 gSystem->Exec(TString::Format("%s %s", kRM, path.Data()));
602 if (!gSystem->AccessPathName(path, kFileExists)) rc1 = -1;
603 path.ReplaceAll("/downloaded/", "/");
604 gSystem->Exec(TString::Format("%s %s", kRM, path.Data()));
605 if (!gSystem->AccessPathName(path, kFileExists)) rc2 = -1;
606 path.Remove(path.Last('.'));
607 gSystem->Exec(TString::Format("%s %s", kRM, path.Data()));
608 if (!gSystem->AccessPathName(path, kFileExists)) rc3 = -1;
609 } else {
610 // Clear all packages
611 rc1 = gSystem->Exec(TString::Format("%s %s/*", kRM, fDir.Data()));
612 }
613 if (dolock) fLock.Unlock();
614 return (rc1 + rc2 + rc3);
615}
616
617////////////////////////////////////////////////////////////////////////////////
618/// Get list of available packages
619/// Returns a pointer to a TList object, transferring ownership to the caller
620
622{
623 TList *plist = new TList;
624 void *dir = gSystem->OpenDirectory(fDir);
625 if (dir) {
626 TString pac(gSystem->GetDirEntry(dir));
627 while (pac.Length() > 0) {
628 if (pac.EndsWith(".par")) {
629 pac.ReplaceAll(".par","");
630 plist->Add(new TObjString(pac.Data()));
631 }
632 pac = gSystem->GetDirEntry(dir);
633 }
634 }
636
637 return plist;
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// Get list of enabled packages
642/// Returns a pointer to a TList object, transferring ownership to the caller
643
645{
646 TList *epl = nullptr;
648 epl = new TList;
650 TObject *o = 0;
651 while ((o = nxp())) {
652 epl->Add(new TObjString(o->GetName()));
653 }
654 }
655 return epl;
656}
657
658////////////////////////////////////////////////////////////////////////////////
659/// Show enabled packages
660///
661
662void TPackMgr::ShowEnabled(const char *title)
663{
665 // Scan the list of global packages dirs
667 TPackMgr *pm = 0;
668 while ((pm = (TPackMgr *)nxpm())) {
669 pm->ShowEnabled(TString::Format("*** Global Package cache %s %s:%s ***\n",
670 pm->GetName(), gSystem->HostName(), pm->GetTitle()));
671 }
672 }
673
674 if (!fEnabledPackages || fEnabledPackages->GetSize() <= 0) return;
675
676 if (title && strlen(title) > 0)
677 printf("%s\n", title);
678 else
679 printf("*** Package enabled on %s ***\n", gSystem->HostName());
680 fflush(stdout);
681
683 while (TPair *pck = (TPair *) next()) {
684 printf("%s\n", pck->GetName());
685 }
686}
687
688////////////////////////////////////////////////////////////////////////////////
689/// Get MD5 checksum of the PAR file corresponding to given package
690/// Returns a pointer to a TMD5 object, transferring ownership to the caller
691
692TMD5 *TPackMgr::GetMD5(const char *pack)
693{
694 // Shared lock from here
696 // PAR file path
697 const char *fm = (strstr(pack, ".par")) ? "%s/%s" : "%s/%s.par";
698 TString parfile = TString::Format(fm, fDir.Data(), pack);
699
700 return TMD5::FileChecksum(parfile);
701}
702
703
704////////////////////////////////////////////////////////////////////////////////
705/// Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
706/// Returns a pointer to a TMD5 object, transferring ownership to the caller
707
708TMD5 *TPackMgr::ReadMD5(const char *pack)
709{
710 TString pn(pack);
711 if (pn.EndsWith(".par")) pn.Remove(pn.Last('.'));
712
713 TString md5f = TString::Format("%s/%s/PROOF-INF/md5.txt", fDir.Data(), pn.Data());
715 return TMD5::ReadChecksum(md5f);
716}
717
718
719////////////////////////////////////////////////////////////////////////////////
720/// Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
721/// Returns a pointer to a TMD5 object, transferring ownership to the caller
722
723Int_t TPackMgr::Unpack(const char *pack, TMD5 *sum)
724{
725 Int_t rc = 0;
726 TString fn(pack), pn(pack);
727 if (!fn.EndsWith(".par")) fn += ".par";
728 if (pn.EndsWith(".par")) pn.Remove(pn.Last('.'));
729
730 // Find gunzip...
731 char *gunzip = gSystem->Which(gSystem->Getenv("PATH"), kGUNZIP, kExecutePermission);
732 if (gunzip) {
733 // untar package
734 TString cmd;
735 cmd.Form(kUNTAR, gunzip, fDir.Data(), fn.Data(), fDir.Data());
736 rc = gSystem->Exec(cmd);
737 if (rc != 0)
738 Error("Unpack", "failure executing: %s (rc: %d)", cmd.Data(), rc);
739 delete [] gunzip;
740 } else {
741 Error("Unpack", "%s not found", kGUNZIP);
742 rc = -2;
743 }
744 // check that fDir/pack now exists
746 // par file did not unpack itself in the expected directory, failure
747 rc = -1;
748 Error("Unpack", "package %s did not unpack into %s", fn.Data(), pn.Data());
749 } else {
750 // store md5 in package/PROOF-INF/md5.txt
751 if (sum) {
752 TString md5f = TString::Format("%s/%s/PROOF-INF/md5.txt", fDir.Data(), pn.Data());
754 }
755 }
756
757 return rc;
758}
759
760////////////////////////////////////////////////////////////////////////////////
761/// Install package from par (unpack the file in the directory); par can be an
762/// URL for remote retrieval. If rmold is kTRUE an existing version of the package
763/// is removed if existing.
764/// Returns 0 on success, <0 otherwise
765
766Int_t TPackMgr::Install(const char *parpath, Bool_t rmold)
767{
768 Int_t rc = 0;
769
770 Info("Install", "installing %s ...", parpath);
771 TString par = parpath;
773
774 // Does par exists?
776 Error("Install", "%s is invalid", par.Data());
777 return -1;
778 }
779 TString parname = gSystem->BaseName(par.Data());
780 TString pack = parname(0, parname.Last('.'));
781 TString dest = TString::Format("%s/%s", fDir.Data(), parname.Data());
782 TString psrc = par, ssrc;
783 TMD5 *sums = 0, *md5 = 0, *md5d = 0;
784
785 // Check if we need to download: get the remote checksum
786 // Retrieve the checksum of the file, if available
787 // Dowload checksum file, if available
788 TString dldir;
789 if (GetDownloadDir(dldir) != 0) {
790 Error("Install", "could not create/get download directory");
791 return -1;
792 }
793
795
796 TString parsum(par);
797 parsum.ReplaceAll(".par", ".md5sum");
798 if (!gSystem->AccessPathName(parsum, kReadPermission)) {
799 ssrc.Form("%s/%s", dldir.Data(), gSystem->BaseName(parsum));
800 if (!TFile::Cp(parsum, ssrc)) {
801 Warning("Install", "could not retrieve %s", parsum.Data());
802 } else {
803 md5 = TMD5::ReadChecksum(ssrc);
804 }
805 }
806
807 // Do we have already the file?
808 Bool_t parexists = (!gSystem->AccessPathName(dest)) ? kTRUE : kFALSE;
809
810 Bool_t install = kTRUE;
811 // If yes and we are asked to clean the old one, do it
812 if (parexists) {
813 install = kFALSE;
814 if (rmold) {
815 // Asked to remove: do it
816 if (Remove(pack, kFALSE) < 0) {
817 Error("Install", "could not remove existing version of '%s'", pack.Data());
818 if (md5) delete md5;
819 return -1;
820 }
821 install = kTRUE;
822 } else {
823 if (!md5) {
825 if (ft == TFile::kWeb || ft == TFile::kNet) {
826 psrc.Form("%s/%s", dldir.Data(), parname.Data());
827 if (!TFile::Cp(par.Data(), psrc)) {
828 Error("Install", "could not retrieve %s", par.Data());
829 return -1;
830 }
831 }
832 // psrc is either the original par or the downloaded path
833 md5 = TMD5::FileChecksum(psrc);
834 }
835 // Now we need to compare with the local one
836 sums = TMD5::FileChecksum(dest);
837 if (sums && md5 && (*sums != *md5)) install = kTRUE;
838 }
839 }
840 if (sums) delete sums;
841
842 // Install if required
843 if (install) {
844 if (!TFile::Cp(psrc, dest)) {
845 Error("Install", "could not copy %s to %s", psrc.Data(), dest.Data());
846 if (md5) delete md5;
847 return -1;
848 }
849 }
850 md5d = TMD5::FileChecksum(dest);
851
852 if (md5 && *md5 != *md5d)
853 Warning("Install", "checksums do not match:\n\tdownloaded:\t%s\n\texpected:\t%s",
854 md5d->AsString(), md5->AsString());
855 if (Unpack(pack, md5d) != 0) {
856 Error("Install", "could not unpack %s", dest.Data());
857 rc = -1;
858 }
859 if (md5) delete md5;
860 if (md5d) delete md5d;
861 return rc;
862}
863
864//---------------------------------------------------------------------------------------------------
865// Static methods
866//---------------------------------------------------------------------------------------------------
867
868////////////////////////////////////////////////////////////////////////////////
869/// Parse one or more paths as possible sources of packages
870/// Returns number of paths added; or -1 in case of problems
871
873{
874 Int_t ng = 0;
875 // List of directories where to look for global packages
876 TString globpack(paths);
877 if (globpack.Length() > 0) {
878 Int_t from = 0;
879 TString ldir;
880 while (globpack.Tokenize(ldir, from, ":")) {
882 ::Warning("TPackMgr::RegisterGlobalPath",
883 "directory for global packages %s does not"
884 " exist or is not readable", ldir.Data());
885 } else {
886 // Add to the list, key will be "G<ng>", i.e. "G0", "G1", ...
887 TString key;
888 key.Form("G%d", ng++);
889 if (!fgGlobalPackMgrList) {
892 }
893 TPackMgr *pmgr = new TPackMgr(ldir);
894 pmgr->SetName(key);
896 ::Info("TPackMgr::RegisterGlobalPath",
897 "manager for global packages directory %s added to the list",
898 ldir.Data());
899 }
900 }
901 }
902 // Number of registered packages
903 return ng;
904}
905
906
907////////////////////////////////////////////////////////////////////////////////
908/// Get the package manager having 'pack'; priority is given to packmgr, if
909/// defined.
910/// Returns packmgr or nullptr
911
912TPackMgr *TPackMgr::GetPackMgr(const char *pack, TPackMgr *packmgr)
913{
914 if (packmgr && packmgr->Has(pack)) return packmgr;
915
917 // Scan the list of global packages managers
919 TPackMgr *pm = 0;
920 while ((pm = (TPackMgr *)nxpm())) {
921 if (pm->Has(pack)) return pm;
922 }
923 }
924 return nullptr;
925}
926
927
928////////////////////////////////////////////////////////////////////////////////
929/// Get the full path to PAR, looking also in the global dirs.
930/// Returns -1 if not found, 0 if available in global dirs, 1 if it can be
931/// uploaded from the local package dir.
932/// For the cases >= 0, par is filled with the path of the PAR file
933
934Int_t TPackMgr::FindParPath(TPackMgr *packmgr, const char *pack, TString &par)
935{
936 // Try the package dir
937 if (packmgr && packmgr->GetParPath(pack, par) == 0) return 1;
938
939 // Try global package dirs
941 // Scan the list of global packages dirs
943 TPackMgr *pm = 0;
944 while ((pm = (TPackMgr *)nxpm())) {
945 if (pm->GetParPath(pack, par) == 0) {
946 // Package found, stop searching
947 break;
948 }
949 par = "";
950 }
951 if (par.Length() > 0) return 0;
952 }
953 return -1;
954}
955
956////////////////////////////////////////////////////////////////////////////////
957/// Check if the package is enabled; priority is given to packmgr, if
958/// defined.
959/// Returns kTRUE if enabled
960
961Bool_t TPackMgr::IsEnabled(const char *pack, TPackMgr *packmgr)
962{
963 if (packmgr && packmgr->IsPackageEnabled(pack)) return kTRUE;
964
966 // Scan the list of global packages managers
968 TPackMgr *pm = 0;
969 while ((pm = (TPackMgr *)nxpm())) {
970 if (pm->IsPackageEnabled(pack)) return kTRUE;
971 }
972 }
973 // Not Enabled
974 return kFALSE;
975}
#define SafeDelete(p)
Definition RConfig.hxx:525
#define f(i)
Definition RSha256.hxx:104
long Longptr_t
Definition RtypesCore.h:75
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
#define gInterpreter
static void DefaultLogger(const char *msg)
Definition TPackMgr.cxx:42
const char *const kRM
Definition TProof.h:142
const char *const kUNTAR
Definition TProof.h:144
const char *const kUNTAR3
Definition TProof.h:146
const char *const kGUNZIP
Definition TProof.h:147
const char *const kLS
Definition TProof.h:143
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:406
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
@ kFileExists
Definition TSystem.h:42
@ kExecutePermission
Definition TSystem.h:43
@ kReadPermission
Definition TSystem.h:45
@ kWritePermission
Definition TSystem.h:44
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
static EFileType GetType(const char *name, Option_t *option="", TString *prefix=nullptr)
Resolve the file type as a function of the protocol field in 'name'.
Definition TFile.cxx:4821
EFileType
File type.
Definition TFile.h:202
@ kWeb
Definition TFile.h:202
@ kNet
Definition TFile.h:202
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t buffersize=1000000)
Allows to copy this file to the dst URL.
Definition TFile.cxx:5003
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
Int_t GetNargs() const
Number of function arguments.
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:83
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
void SetName(const char *path)
Definition TLockPath.h:36
Int_t Lock(Bool_t shared=kFALSE)
Definition TLockPath.cxx:43
Int_t Unlock()
Unlock the directory.
Definition TLockPath.cxx:80
This code implements the MD5 message-digest algorithm.
Definition TMD5.h:44
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition TMD5.cxx:474
static TMD5 * ReadChecksum(const char *file)
Returns checksum stored in ASCII in specified file.
Definition TMD5.cxx:422
static Int_t WriteChecksum(const char *file, const TMD5 *md5)
Writes checksum in ASCII format to specified file.
Definition TMD5.cxx:452
Class supporting a collection of lines with C++ code.
Definition TMacro.h:31
virtual Bool_t Load() const
Load the macro into the interpreter.
Definition TMacro.cxx:244
virtual Int_t ReadFile(const char *filename)
Read lines in filename in this macro.
Definition TMacro.cxx:329
TList * GetListOfLines() const
Definition TMacro.h:51
virtual TObjString * GetLineWith(const char *text) const
Search the first line containing text.
Definition TMacro.cxx:297
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
Method or function calling interface.
Definition TMethodCall.h:37
void ResetParam()
Reset parameter list. To be used before the first call the SetParam().
void Execute(const char *, const char *, int *=nullptr) override
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
void SetParam(Long_t l)
Add a long method parameter.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
ULong_t Hash() const override
Return hash value for this object.
Definition TNamed.h:49
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
void SetString(const char *s)
Definition TObjString.h:45
const char * GetName() const override
Returns name of object.
Definition TObjString.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:438
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:402
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
The PROOF package manager contains tools to manage packages.
Definition TPackMgr.h:37
Bool_t IsInDir(const char *path)
Method to check if 'path' is in the managed directory Return kTRUE or kFALSE.
Definition TPackMgr.cxx:478
@ kCheckROOT
Definition TPackMgr.h:39
const char * GetTitle() const override
Returns title of object.
Definition TPackMgr.h:63
TString fDir
Definition TPackMgr.h:44
void Show(const char *title=0)
Show available packages.
Definition TPackMgr.cxx:548
void GetEnabledPackages(TString &packlist)
Method to get a semi-colon separated list with the names of the enabled packages.
Definition TPackMgr.cxx:501
static Bool_t IsEnabled(const char *pack, TPackMgr *packmgr=nullptr)
Check if the package is enabled; priority is given to packmgr, if defined.
Definition TPackMgr.cxx:961
Int_t GetPackDir(const char *pack, TString &pdir)
Method to get the path of the dir for package 'pack'.
Definition TPackMgr.cxx:487
static THashList * fgGlobalPackMgrList
Definition TPackMgr.h:49
Int_t Build(const char *pack, Int_t opt=TPackMgr::kCheckROOT)
Method to build a package.
Definition TPackMgr.cxx:87
Int_t Install(const char *par, Bool_t rmold=kFALSE)
Install package from par (unpack the file in the directory); par can be an URL for remote retrieval.
Definition TPackMgr.cxx:766
Int_t GetParPath(const char *pack, TString &path)
Method to get the path of the PAR file for package 'pack'.
Definition TPackMgr.cxx:521
Int_t GetDownloadDir(TString &dldir)
Method to get the download dir; create if not existing Return -1 in case of error (not found; not cre...
Definition TPackMgr.cxx:534
Bool_t Has(const char *pack)
Method to check if this package manager has package 'pack'.
Definition TPackMgr.cxx:458
Int_t Unpack(const char *pack, TMD5 *sum=0)
Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
Definition TPackMgr.cxx:723
TMD5 * GetMD5(const char *pack)
Get MD5 checksum of the PAR file corresponding to given package Returns a pointer to a TMD5 object,...
Definition TPackMgr.cxx:692
void ShowEnabled(const char *title=0)
Show enabled packages.
Definition TPackMgr.cxx:662
void Log(const char *msg)
Wrapper to notofuer / logger.
Definition TPackMgr.cxx:73
TLockPath fLock
Definition TPackMgr.h:45
static Int_t FindParPath(TPackMgr *packmgr, const char *pack, TString &par)
Get the full path to PAR, looking also in the global dirs.
Definition TPackMgr.cxx:934
TList * GetList() const
Get list of available packages Returns a pointer to a TList object, transferring ownership to the cal...
Definition TPackMgr.cxx:621
TPackMgr(const TPackMgr &)
Int_t Clean(const char *pack)
Clean dir for package 'pack' Return -1 in case of error, 0 otherwise.
Definition TPackMgr.cxx:576
static Int_t RegisterGlobalPath(const char *paths)
Parse one or more paths as possible sources of packages Returns number of paths added; or -1 in case ...
Definition TPackMgr.cxx:872
Bool_t IsPackageEnabled(const char *pack)
Definition TPackMgr.h:82
Int_t Load(const char *pack, TList *optls=0)
Method to load a package taking an option list Return -1 on error, 0 otherwise.
Definition TPackMgr.cxx:220
Int_t Unload(const char *pack)
Method to unload a package.
Definition TPackMgr.cxx:411
const char * GetName() const override
Returns name of object.
Definition TPackMgr.h:61
TPackMgrLog_t fLogger
Definition TPackMgr.h:42
TList * fEnabledPackages
Definition TPackMgr.h:47
TList * GetListOfEnabled() const
Get list of enabled packages Returns a pointer to a TList object, transferring ownership to the calle...
Definition TPackMgr.cxx:644
~TPackMgr() override
Destroy a TPackMgr instance.
Definition TPackMgr.cxx:64
static TPackMgr * GetPackMgr(const char *pack, TPackMgr *packmgr=nullptr)
Get the package manager having 'pack'; priority is given to packmgr, if defined.
Definition TPackMgr.cxx:912
void SetName(const char *name) override
Set the name of the TNamed.
Definition TPackMgr.h:62
TString fPfx
Definition TPackMgr.h:46
Int_t Remove(const char *pack=0, Bool_t dolock=kTRUE)
Remove package 'pack' If 'pack' is null or empty all packages are cleared.
Definition TPackMgr.cxx:593
TMD5 * ReadMD5(const char *pack)
Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
Definition TPackMgr.cxx:708
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
const char * GetName() const override
Returns name of object.
Definition TMap.h:116
Named parameter, streamable and storable.
Definition TParameter.h:35
const AParamType & GetVal() const
Definition TParameter.h:67
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:931
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2264
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
Bool_t IsNull() const
Definition TString.h:414
TString & Remove(Ssiz_t pos)
Definition TString.h:685
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
virtual int Symlink(const char *from, const char *to)
Create a symbolic link from file1 to file2.
Definition TSystem.cxx:1368
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274
virtual void AddIncludePath(const char *includePath)
Add a directory to the already set include path.
Definition TSystem.cxx:4159
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:845
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition TSystem.cxx:836
virtual int GetPid()
Get process id.
Definition TSystem.cxx:707
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1665
virtual const char * GetIncludePath()
Get the list of include path.
Definition TSystem.cxx:3973
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition TSystem.cxx:906
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:653
virtual void SetIncludePath(const char *includePath)
IncludePath should contain the list of compiler flags to indicate where to find user defined header f...
Definition TSystem.cxx:4194
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1296
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:853
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:862
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:934
virtual const char * HostName()
Return the system's host name.
Definition TSystem.cxx:303
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:871
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1548
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1381
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition TSystem.cxx:1482
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345