26 #include "gapi_dir_operations.h"
27 #include "gapi_file_operations.h"
28 #include "gapi_stat.h"
30 ClassImp(TAlienSystem);
35 TAlienSystem::TAlienSystem(
const char *name,
const char *title) : TSystem(name, title)
37 fWorkingDirectory[0] =
'\0';
43 TAlienSystem::~TAlienSystem()
50 Bool_t TAlienSystem::Init()
60 int TAlienSystem::MakeDirectory(
const char* dirname)
65 if (strcmp(gGrid->GetGrid(),
"alien")) {
66 Error(
"TAlienSystem",
"You are not connected to AliEn");
71 url.CleanRelativePath();
72 if (strcmp(url.GetProtocol(),
"alien")) {
73 Info(
"OpenDirectory",
"Assuming an AliEn URL alien://%s",dirname);
74 url.SetProtocol(
"alien",kTRUE);
76 return gapi_mkdir(url.GetUrl(),0);
82 void *TAlienSystem::OpenDirectory(
const char* name)
85 url.CleanRelativePath();
86 if (strcmp(url.GetProtocol(),
"alien")) {
87 Info(
"OpenDirectory",
"Assuming an AliEn URL alien://%s",name);
88 url.SetProtocol(
"alien",kTRUE);
90 return (
void*) gapi_opendir(url.GetUrl());
96 void TAlienSystem::FreeDirectory(
void* ptr)
98 gapi_closedir( (GAPI_DIR*)ptr);
105 const char *TAlienSystem::GetDirEntry(
void* ptr)
107 struct dirent* retdir;
108 retdir = gapi_readdir( (GAPI_DIR*) ptr);
111 return retdir->d_name;
120 Bool_t TAlienSystem::ChangeDirectory(
const char* dirname)
123 url.CleanRelativePath();
124 if (strcmp(url.GetProtocol(),
"alien")) {
125 Info(
"OpenDirectory",
"Assuming an AliEn URL alien://%s",dirname);
126 url.SetProtocol(
"alien",kTRUE);
128 return gapi_chdir(url.GetUrl());
135 const char *TAlienSystem::WorkingDirectory()
137 return gapi_getcwd(fWorkingDirectory,1024);
143 const char *TAlienSystem::HomeDirectory(
const char*)
148 if (strcmp(gGrid->GetGrid(),
"alien")) {
149 Error(
"TAlienSystem",
"You are not connected to AliEn");
152 return (gGrid->GetHomeDirectory());
161 int TAlienSystem::mkdir(
const char *name, Bool_t recursive)
164 TString dirname = DirName(name);
165 if (dirname.Length()==0) {
170 if (AccessPathName(dirname, kFileExists)) {
171 int res = mkdir(dirname, kTRUE);
174 if (!AccessPathName(name, kFileExists)) {
179 return MakeDirectory(name);
187 int TAlienSystem::CopyFile(
const char *,
const char *, Bool_t)
189 AbstractMethod(
"CopyFile");
196 int TAlienSystem::Rename(
const char *oldname,
const char *newname)
198 return gapi_rename(oldname,newname);
206 int TAlienSystem::Link(
const char *,
const char *)
208 AbstractMethod(
"Link");
215 int TAlienSystem::Symlink(
const char *,
const char *)
217 AbstractMethod(
"Symlink");
224 int TAlienSystem::Unlink(
const char * filename)
226 return gapi_unlink(filename);
242 int TAlienSystem::GetPathInfo(
const char *path, Long_t *
id, Long_t *size,
243 Long_t *flags, Long_t *modtime)
247 int res = GetPathInfo(path,
id, &lsize, flags, modtime);
249 if (res == 0 && size) {
250 if (
sizeof(Long_t) == 4 && lsize > kMaxInt) {
251 Error(
"GetPathInfo",
"file %s > 2 GB, use GetPathInfo() with Long64_t size", path);
254 *size = (Long_t)lsize;
272 int TAlienSystem::GetPathInfo(
const char *path, Long_t *
id, Long64_t *size,
273 Long_t *flags, Long_t *modtime)
277 int res = GetPathInfo(path, buf);
281 *
id = (buf.fDev << 24) + buf.fIno;
285 *modtime = buf.fMtime;
288 if (buf.fMode & (kS_IXUSR|kS_IXGRP|kS_IXOTH))
290 if (R_ISDIR(buf.fMode))
292 if (!R_ISREG(buf.fMode) && !R_ISDIR(buf.fMode))
306 int TAlienSystem::GetPathInfo(
const char *path, FileStat_t &buf)
309 return AlienFilestat(path,buf);
318 int TAlienSystem::AlienFilestat(
const char *fpath, FileStat_t &buf)
321 url.CleanRelativePath();
322 if (strcmp(url.GetProtocol(),
"alien")) {
323 Info(
"AlienFilestat",
"Assuming an AliEn URL alien://%s",fpath);
324 url.SetProtocol(
"alien",kTRUE);
326 #if defined(R__SEEK64)
328 if ((gapi_lstat(url.GetUrl(), (GAPI_STAT*)(&sbuf))) == 0) {
331 if ((gapi_lstat(url.GetUrl(), (GAPI_STAT*)(&sbuf))) == 0) {
333 buf.fIsLink = S_ISLNK(sbuf.st_mode);
334 buf.fDev = sbuf.st_dev;
335 buf.fIno = sbuf.st_ino;
336 buf.fMode = sbuf.st_mode;
337 buf.fUid = sbuf.st_uid;
338 buf.fGid = sbuf.st_gid;
339 buf.fSize = sbuf.st_size;
340 buf.fMtime = sbuf.st_mtime;
351 int TAlienSystem::GetFsInfo(
const char *, Long_t *, Long_t *, Long_t *, Long_t *)
353 AbstractMethod(
"GetFsInfo");
360 int TAlienSystem::Chmod(
const char *file, UInt_t mode)
363 url.CleanRelativePath();
364 if (strcmp(url.GetProtocol(),
"alien")) {
365 Info(
"AlienFilestat",
"Assuming an AliEn URL alien://%s",file);
366 url.SetProtocol(
"alien",kTRUE);
368 return gapi_chmod(url.GetUrl(),mode);
374 int TAlienSystem::Umask(Int_t)
376 AbstractMethod(
"Umask");
384 int TAlienSystem::Utime(
const char *, Long_t, Long_t)
386 AbstractMethod(
"Utime");
394 const char *TAlienSystem::FindFile(
const char *, TString&, EAccessMode)
396 AbstractMethod(
"Which");
406 Bool_t TAlienSystem::AccessPathName(
const char *path, EAccessMode mode)
411 if (strcmp(gGrid->GetGrid(),
"alien")) {
412 Error(
"TAlienSystem",
"You are not connected to AliEn");
416 TString strippath = path ;
418 while (strippath.EndsWith(
"/")) {strippath.Remove(strippath.Length()-1);}
420 url.CleanRelativePath();
422 if (strcmp(url.GetProtocol(),
"alien")) {
423 Info(
"AccessPathName",
"Assuming an AliEn URL alien://%s",path);
424 url.SetProtocol(
"alien",kTRUE);
426 if(!gapi_access(url.GetUrl(),mode)) {
439 Int_t TAlienSystem::GetUid(
const char * )
441 AbstractMethod(
"GetUid");
449 Int_t TAlienSystem::GetEffectiveUid()
451 AbstractMethod(
"GetEffectiveUid");
458 Int_t TAlienSystem::GetGid(
const char * )
460 AbstractMethod(
"GetGid");
468 Int_t TAlienSystem::GetEffectiveGid()
470 AbstractMethod(
"GetEffectiveGid");
478 UserGroup_t *TAlienSystem::GetUserInfo(Int_t )
480 AbstractMethod(
"GetUserInfo");
489 UserGroup_t *TAlienSystem::GetUserInfo(
const char * )
491 AbstractMethod(
"GetUserInfo");
502 UserGroup_t *TAlienSystem::GetGroupInfo(Int_t )
504 AbstractMethod(
"GetGroupInfo");
515 UserGroup_t *TAlienSystem::GetGroupInfo(
const char * )
517 AbstractMethod(
"GetGroupInfo");