00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <errno.h>
00020
00021 #include "Riostream.h"
00022 #include "TAlienSystem.h"
00023 #include "TError.h"
00024 #include "TUrl.h"
00025 #include "TGrid.h"
00026 #include "gapi_dir_operations.h"
00027 #include "gapi_file_operations.h"
00028 #include "gapi_stat.h"
00029
00030 ClassImp(TAlienSystem)
00031
00032
00033 TAlienSystem::TAlienSystem(const char *name, const char *title) : TSystem(name, title)
00034 {
00035
00036 }
00037
00038
00039 TAlienSystem::~TAlienSystem()
00040 {
00041
00042 }
00043
00044
00045 Bool_t TAlienSystem::Init()
00046 {
00047
00048 return kTRUE;
00049 }
00050
00051
00052 int TAlienSystem::MakeDirectory(const char* dirname)
00053 {
00054
00055
00056
00057
00058 if (!gGrid)
00059 return -1;
00060
00061 if (strcmp(gGrid->GetGrid(),"alien")) {
00062 Error("TAlienSystem","You are not connected to AliEn");
00063 return -1;
00064 }
00065
00066 TUrl url(dirname);
00067 url.CleanRelativePath();
00068 if (strcmp(url.GetProtocol(),"alien")) {
00069 Info("OpenDirectory","Assuming an AliEn URL alien://%s",dirname);
00070 url.SetProtocol("alien",kTRUE);
00071 }
00072 return gapi_mkdir(url.GetUrl(),0);
00073 }
00074
00075
00076 void *TAlienSystem::OpenDirectory(const char* name)
00077 {
00078
00079 TUrl url(name);
00080 url.CleanRelativePath();
00081 if (strcmp(url.GetProtocol(),"alien")) {
00082 Info("OpenDirectory","Assuming an AliEn URL alien://%s",name);
00083 url.SetProtocol("alien",kTRUE);
00084 }
00085 return (void*) gapi_opendir(url.GetUrl());
00086
00087 AbstractMethod("OpenDirectory");
00088 return 0;
00089 }
00090
00091
00092 void TAlienSystem::FreeDirectory(void* ptr)
00093 {
00094
00095 gapi_closedir( (GAPI_DIR*)ptr);
00096 return;
00097 AbstractMethod("FreeDirectory");
00098 }
00099
00100
00101 const char *TAlienSystem::GetDirEntry(void* ptr)
00102 {
00103
00104 struct dirent* retdir;
00105 retdir = gapi_readdir( (GAPI_DIR*) ptr);
00106
00107 if (retdir)
00108 return retdir->d_name;
00109 return 0;
00110 }
00111
00112
00113 Bool_t TAlienSystem::ChangeDirectory(const char* dirname)
00114 {
00115
00116
00117
00118
00119 TUrl url(dirname);
00120 url.CleanRelativePath();
00121 if (strcmp(url.GetProtocol(),"alien")) {
00122 Info("OpenDirectory","Assuming an AliEn URL alien://%s",dirname);
00123 url.SetProtocol("alien",kTRUE);
00124 }
00125 return gapi_chdir(url.GetUrl());
00126
00127 }
00128
00129
00130 const char *TAlienSystem::WorkingDirectory()
00131 {
00132
00133 return gapi_getcwd(fWorkingDirectory,1024);
00134 }
00135
00136
00137 const char *TAlienSystem::HomeDirectory(const char*)
00138 {
00139
00140 if (!gGrid)
00141 return 0;
00142
00143 if (strcmp(gGrid->GetGrid(),"alien")) {
00144 Error("TAlienSystem","You are not connected to AliEn");
00145 return 0;
00146 }
00147 return (gGrid->GetHomeDirectory());
00148 }
00149
00150
00151 int TAlienSystem::mkdir(const char *name, Bool_t recursive)
00152 {
00153
00154
00155
00156
00157
00158 if (recursive) {
00159 TString dirname = DirName(name);
00160 if (dirname.Length()==0) {
00161
00162
00163 return -1;
00164 }
00165 if (AccessPathName(dirname, kFileExists)) {
00166 int res = mkdir(dirname, kTRUE);
00167 if (res) return res;
00168 }
00169 if (!AccessPathName(name, kFileExists)) {
00170 return -1;
00171 }
00172 }
00173
00174 return MakeDirectory(name);
00175 }
00176
00177
00178 int TAlienSystem::CopyFile(const char *, const char *, Bool_t)
00179 {
00180
00181
00182
00183
00184 AbstractMethod("CopyFile");
00185 return -1;
00186 }
00187
00188
00189 int TAlienSystem::Rename(const char *oldname, const char *newname)
00190 {
00191
00192 return gapi_rename(oldname,newname);
00193
00194
00195 }
00196
00197
00198 int TAlienSystem::Link(const char *, const char *)
00199 {
00200
00201
00202 AbstractMethod("Link");
00203 return -1;
00204 }
00205
00206
00207 int TAlienSystem::Symlink(const char *, const char *)
00208 {
00209
00210
00211 AbstractMethod("Symlink");
00212 return -1;
00213 }
00214
00215
00216 int TAlienSystem::Unlink(const char * filename)
00217 {
00218
00219
00220 return gapi_unlink(filename);
00221
00222
00223 }
00224
00225
00226 int TAlienSystem::GetPathInfo(const char *path, Long_t *id, Long_t *size,
00227 Long_t *flags, Long_t *modtime)
00228 {
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 Long64_t lsize;
00240
00241 int res = GetPathInfo(path, id, &lsize, flags, modtime);
00242
00243 if (res == 0 && size) {
00244 if (sizeof(Long_t) == 4 && lsize > kMaxInt) {
00245 Error("GetPathInfo", "file %s > 2 GB, use GetPathInfo() with Long64_t size", path);
00246 *size = kMaxInt;
00247 } else {
00248 *size = (Long_t)lsize;
00249 }
00250 }
00251
00252 return res;
00253 }
00254
00255
00256 int TAlienSystem::GetPathInfo(const char *path, Long_t *id, Long64_t *size,
00257 Long_t *flags, Long_t *modtime)
00258 {
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 FileStat_t buf;
00270
00271 int res = GetPathInfo(path, buf);
00272
00273 if (res == 0) {
00274 if (id)
00275 *id = (buf.fDev << 24) + buf.fIno;
00276 if (size)
00277 *size = buf.fSize;
00278 if (modtime)
00279 *modtime = buf.fMtime;
00280 if (flags) {
00281 *flags = 0;
00282 if (buf.fMode & (kS_IXUSR|kS_IXGRP|kS_IXOTH))
00283 *flags |= 1;
00284 if (R_ISDIR(buf.fMode))
00285 *flags |= 2;
00286 if (!R_ISREG(buf.fMode) && !R_ISDIR(buf.fMode))
00287 *flags |= 4;
00288 }
00289 }
00290
00291 return res;
00292 }
00293
00294
00295 int TAlienSystem::GetPathInfo(const char *path, FileStat_t &buf)
00296 {
00297
00298
00299
00300
00301
00302
00303 return AlienFilestat(path,buf);
00304 }
00305
00306
00307 int TAlienSystem::AlienFilestat(const char *fpath, FileStat_t &buf)
00308 {
00309
00310
00311
00312
00313
00314 TUrl url(fpath);
00315 url.CleanRelativePath();
00316 if (strcmp(url.GetProtocol(),"alien")) {
00317 Info("AlienFilestat","Assuming an AliEn URL alien://%s",fpath);
00318 url.SetProtocol("alien",kTRUE);
00319 }
00320 #if defined(R__SEEK64)
00321 struct stat64 sbuf;
00322 if ((gapi_lstat(url.GetUrl(), (GAPI_STAT*)(&sbuf))) == 0) {
00323 #else
00324 struct stat sbuf;
00325 if ((gapi_lstat(url.GetUrl(), (GAPI_STAT*)(&sbuf))) == 0) {
00326 #endif
00327 buf.fIsLink = S_ISLNK(sbuf.st_mode);
00328 buf.fDev = sbuf.st_dev;
00329 buf.fIno = sbuf.st_ino;
00330 buf.fMode = sbuf.st_mode;
00331 buf.fUid = sbuf.st_uid;
00332 buf.fGid = sbuf.st_gid;
00333 buf.fSize = sbuf.st_size;
00334 buf.fMtime = sbuf.st_mtime;
00335
00336 return 0;
00337 }
00338 return 1;
00339 }
00340
00341
00342 int TAlienSystem::GetFsInfo(const char *, Long_t *, Long_t *, Long_t *, Long_t *)
00343 {
00344
00345
00346
00347 AbstractMethod("GetFsInfo");
00348 return 1;
00349 }
00350
00351
00352 int TAlienSystem::Chmod(const char *file, UInt_t mode)
00353 {
00354
00355 TUrl url(file);
00356 url.CleanRelativePath();
00357 if (strcmp(url.GetProtocol(),"alien")) {
00358 Info("AlienFilestat","Assuming an AliEn URL alien://%s",file);
00359 url.SetProtocol("alien",kTRUE);
00360 }
00361 return gapi_chmod(url.GetUrl(),mode);
00362 }
00363
00364
00365 int TAlienSystem::Umask(Int_t)
00366 {
00367
00368
00369 AbstractMethod("Umask");
00370 return -1;
00371 }
00372
00373
00374 int TAlienSystem::Utime(const char *, Long_t, Long_t)
00375 {
00376
00377
00378
00379 AbstractMethod("Utime");
00380 return -1;
00381 }
00382
00383
00384 const char *TAlienSystem::FindFile(const char *, TString&, EAccessMode)
00385 {
00386
00387
00388
00389 AbstractMethod("Which");
00390 return 0;
00391 }
00392
00393
00394 Bool_t TAlienSystem::AccessPathName(const char *path, EAccessMode mode)
00395 {
00396
00397
00398
00399
00400
00401 if (!gGrid)
00402 return -1;
00403
00404 if (strcmp(gGrid->GetGrid(),"alien")) {
00405 Error("TAlienSystem","You are not connected to AliEn");
00406 return -1;
00407 }
00408
00409 TString strippath = path ;
00410
00411 while (strippath.EndsWith("/")) {strippath.Remove(strippath.Length()-1);}
00412 TUrl url(strippath);
00413 url.CleanRelativePath();
00414
00415 if (strcmp(url.GetProtocol(),"alien")) {
00416 Info("AccessPathName","Assuming an AliEn URL alien://%s",path);
00417 url.SetProtocol("alien",kTRUE);
00418 }
00419 if(!gapi_access(url.GetUrl(),mode)) {
00420 return kFALSE;
00421 } else {
00422 return kTRUE;
00423 }
00424 }
00425
00426
00427
00428
00429
00430 Int_t TAlienSystem::GetUid(const char * )
00431 {
00432
00433
00434 AbstractMethod("GetUid");
00435 return 0;
00436 }
00437
00438
00439 Int_t TAlienSystem::GetEffectiveUid()
00440 {
00441
00442
00443
00444 AbstractMethod("GetEffectiveUid");
00445 return 0;
00446 }
00447
00448
00449 Int_t TAlienSystem::GetGid(const char * )
00450 {
00451
00452
00453 AbstractMethod("GetGid");
00454 return 0;
00455 }
00456
00457
00458 Int_t TAlienSystem::GetEffectiveGid()
00459 {
00460
00461
00462
00463 AbstractMethod("GetEffectiveGid");
00464 return 0;
00465 }
00466
00467
00468 UserGroup_t *TAlienSystem::GetUserInfo(Int_t )
00469 {
00470
00471
00472
00473 AbstractMethod("GetUserInfo");
00474 return 0;
00475 }
00476
00477
00478 UserGroup_t *TAlienSystem::GetUserInfo(const char * )
00479 {
00480
00481
00482
00483
00484 AbstractMethod("GetUserInfo");
00485 return 0;
00486 }
00487
00488
00489 UserGroup_t *TAlienSystem::GetGroupInfo(Int_t )
00490 {
00491
00492
00493
00494
00495
00496
00497 AbstractMethod("GetGroupInfo");
00498 return 0;
00499 }
00500
00501
00502 UserGroup_t *TAlienSystem::GetGroupInfo(const char * )
00503 {
00504
00505
00506
00507
00508
00509
00510 AbstractMethod("GetGroupInfo");
00511 return 0;
00512 }