Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDavixSystem.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Adrien Devresse and Fabrizio Furano
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, 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//////////////////////////////////////////////////////////////////////////
13// //
14// TDavixSystem //
15// //
16// A TSystem specialization for HTTP and WebDAV //
17// It supports HTTP and HTTPS in a number of dialects and options //
18// e.g. S3 is one of them //
19// Other caracteristics come from the full support of Davix, //
20// e.g. full redirection support in any circumstance //
21// //
22// Authors: Adrien Devresse (CERN IT/SDC) //
23// Fabrizio Furano (CERN IT/SDC) //
24// //
25// September 2013 //
26// //
27//////////////////////////////////////////////////////////////////////////
28
29#include "TDavixSystem.h"
30#include "TROOT.h"
31#include "TSocket.h"
32#include "Bytes.h"
33#include "TError.h"
34#include "TBase64.h"
35#include "TVirtualPerfStats.h"
36#include "TDavixFileInternal.h"
37
38#include <cerrno>
39#include <cstdlib>
40#include <unistd.h>
41#include <fcntl.h>
42#include <davix.hpp>
43#include <sstream>
44#include <string>
45#include <cstring>
46
47
48extern const std::string VERSION;
49extern const std::string gUserAgent;
50
51// The prefix that is used to find the variables in the gEnv
52#define ENVPFX "Davix."
53
54
55using namespace Davix;
56
57extern const char* grid_mode_opt;
58extern const char* ca_check_opt;
59extern const char* s3_seckey_opt;
60extern const char* s3_acckey_opt;
61
62////////////////////////////////////////////////////////////////////////////////
63
65 TSystem(url),
66 d_ptr(new TDavixFileInternal(url, "WEB"))
67{
68 d_ptr->init();
69 SetTitle("WebDAV system administration");
70}
71
72////////////////////////////////////////////////////////////////////////////////
73
75 TSystem(),
76 d_ptr(new TDavixFileInternal("", "WEB"))
77{
78 d_ptr->init();
79 SetTitle("WebDAV system administration");
80}
81
82////////////////////////////////////////////////////////////////////////////////
83
88
89////////////////////////////////////////////////////////////////////////////////
90
92{
93 d_ptr->davixPosix->closedir(static_cast<DAVIX_DIR *>(dirp), NULL);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98
100{
101 struct dirent *dir;
103 if (((dir = d_ptr->davixPosix->readdir(static_cast<DAVIX_DIR *>(dirp), &davixErr)) == NULL)
104 && (davixErr != NULL)) {
105 Error("DavixReaddir", "failed to readdir the directory: %s (%d)",
106 davixErr->getErrMsg().c_str(), davixErr->getStatus());
107 DavixError::clearError(&davixErr);
108 }
109 return (dir) ? (dir->d_name) : NULL;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113
114void *TDavixSystem::OpenDirectory(const char *dir)
115{
117 DAVIX_DIR *d;
118 if ((d = d_ptr->davixPosix->opendir(d_ptr->davixParam, dir, &davixErr)) == NULL) {
119 Error("DavixOpendir", "failed to opendir the directory: %s (%d)",
120 davixErr->getErrMsg().c_str(), davixErr->getStatus());
121 DavixError::clearError(&davixErr);
122 } else {
123 d_ptr->addDird(d);
124 }
125 return d;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129
130Bool_t TDavixSystem::ConsistentWith(const char * /*path*/, void *dirptr)
131{
132 return (Bool_t) d_ptr->isMyDird(dirptr);
133}
134
135////////////////////////////////////////////////////////////////////////////////
136
138{
139 struct stat st;
140
141 if (!d_ptr->DavixStat(path, &st)) return 1;
142 buf.fDev = 0;
143 buf.fIno = 0;
144 buf.fMode = st.st_mode; // protection (combination of EFileModeMask bits)
145
146 buf.fUid = st.st_uid; // user id of owner
147 buf.fGid = st.st_gid; // group id of owner
148 buf.fSize = st.st_size; // total size in bytes
149 buf.fMtime = st.st_mtime; // modification date
150 buf.fIsLink = kFALSE; // symbolic link
151 buf.fUrl = path; // end point url of file
152
153 return 0;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157
159{
160 (void) path;
161 return kFALSE;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165
167{
169 ssize_t ret;
171 DavFile f(*d_ptr->davixContext, Uri(path));
172 if ((ret = f.getAllReplicas(d_ptr->davixParam,
173 vecRep,
174 &davixErr)) < 0) {
175 Error("DavixLocate", "failed to Locate file: %s (%d)",
176 davixErr->getErrMsg().c_str(), davixErr->getStatus());
177 DavixError::clearError(&davixErr);
178 return 1;
179 }
180 if (vecRep.size() > 0) {
181 endurl = vecRep[0].uri.getString().c_str();
182 } else {
183 endurl = path;
184 }
185 if (gDebug > 0)
186 Info("DavixLocate", "Davix Locate %s to %s", path, endurl.Data());
187
188 return 0;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192
194{
196 int ret;
197 if ((ret = d_ptr->davixPosix->mkdir(d_ptr->davixParam, dir, 0755, &davixErr)) < 0) {
198 Error("DavixMkdir", "failed to create the directory: %s (%d)",
199 davixErr->getErrMsg().c_str(), davixErr->getStatus());
200 DavixError::clearError(&davixErr);
201 }
202 return ret;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206
207int TDavixSystem::Unlink(const char *path)
208{
210 int ret;
211 if ((ret = d_ptr->davixPosix->unlink(d_ptr->davixParam, path, &davixErr)) < 0) {
212 Error("DavixUnlink", "failed to unlink the file: %s (%d)",
213 davixErr->getErrMsg().c_str(), davixErr->getStatus());
214 DavixError::clearError(&davixErr);
215 }
216 return ret;
217}
#define SafeDelete(p)
Definition RConfig.hxx:533
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const char * s3_seckey_opt
const std::string VERSION
const char * ca_check_opt
const char * s3_acckey_opt
const char * grid_mode_opt
const std::string gUserAgent
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
void addDird(void *fd)
Davix::RequestParams * davixParam
bool isMyDird(void *fd)
Davix::DavPosix * davixPosix
Int_t DavixStat(const char *url, struct stat *st)
Davix::Context * davixContext
void removeDird(void *fd)
Bool_t ConsistentWith(const char *path, void *dirptr) override
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Int_t MakeDirectory(const char *dir) override
Make a directory.
void FreeDirectory(void *dirp) override
Free a directory.
virtual ~TDavixSystem()
virtual Int_t Locate(const char *path, TString &endurl)
const char * GetDirEntry(void *dirp) override
Get a directory entry. Returns 0 if no more entries.
TDavixFileInternal * d_ptr
Bool_t IsPathLocal(const char *path) override
Returns TRUE if the url in 'path' points to the local file system.
Int_t GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
int Unlink(const char *path) override
Unlink, i.e.
void * OpenDirectory(const char *dir) override
Open a directory.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Basic string class.
Definition TString.h:138
Abstract base class defining a generic interface to the underlying Operating System.
Definition TSystem.h:276
Int_t fMode
Definition TSystem.h:135
Long64_t fSize
Definition TSystem.h:138
Long_t fDev
Definition TSystem.h:133
TString fUrl
Definition TSystem.h:141
Int_t fGid
Definition TSystem.h:137
Long_t fMtime
Definition TSystem.h:139
Long_t fIno
Definition TSystem.h:134
Bool_t fIsLink
Definition TSystem.h:140
Int_t fUid
Definition TSystem.h:136