#include <Utilities/StorageFactory/interface/RemoteFile.h>
Public Member Functions | |
~RemoteFile (void) | |
Static Public Member Functions | |
static Storage * | get (int localfd, const std::string &name, char **cmd, int mode) |
static int | local (const std::string &tmpdir, std::string &temp) |
Protected Member Functions | |
virtual void | abort (void) |
Close the file and ignore all errors. | |
virtual void | close (void) |
Close the file. | |
Private Member Functions | |
RemoteFile (IOFD fd, const std::string &name) | |
void | remove (void) |
Private Attributes | |
std::string | name_ |
Definition at line 7 of file RemoteFile.h.
RemoteFile::~RemoteFile | ( | void | ) | [inline] |
RemoteFile::RemoteFile | ( | IOFD | fd, | |
const std::string & | name | |||
) | [private] |
Close the file and ignore all errors.
Reimplemented from File.
Definition at line 45 of file RemoteFile.cc.
References File::abort().
00046 { remove(); File::abort (); }
Close the file.
Reimplemented from File.
Definition at line 41 of file RemoteFile.cc.
References File::close().
Referenced by get().
00042 { remove(); File::close (); }
Definition at line 84 of file RemoteFile.cc.
References close(), environ, Exception, join(), IOFlags::OpenCreate, IOFlags::OpenWrite, RemoteFile(), and throwStorageError().
Referenced by HttpStorageMaker::open(), and GsiFTPStorageMaker::open().
00085 { 00086 // FIXME: On write, create a temporary local file open for write; 00087 // on close, trigger transfer to destination. If opening existing 00088 // file for write, may need to first download. 00089 assert (! (mode & (IOFlags::OpenWrite | IOFlags::OpenCreate))); 00090 00091 pid_t pid = -1; 00092 int rc = posix_spawnp (&pid, cmd[0], 0, 0, cmd, environ); 00093 00094 if (rc == -1) 00095 { 00096 ::close (localfd); 00097 unlink (name.c_str()); 00098 throwStorageError ("RemoteFile::get()", "posix_spawnp()", rc); 00099 } 00100 00101 pid_t rcpid; 00102 do 00103 rcpid = waitpid(pid, &rc, 0); 00104 while (rcpid == (pid_t) -1 && errno == EINTR); 00105 00106 if (rcpid == (pid_t) -1) 00107 { 00108 ::close (localfd); 00109 unlink (name.c_str()); 00110 throwStorageError ("RemoteFile::get()", "waitpid()", errno); 00111 } 00112 00113 if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0) 00114 return new RemoteFile (localfd, name); 00115 else 00116 { 00117 ::close (localfd); 00118 unlink (name.c_str()); 00119 throw cms::Exception("RemoteFile::get()") 00120 << "'" << join(cmd) << "'" 00121 << (WIFEXITED(rc) ? " exited with exit code " 00122 : WIFSIGNALED(rc) ? " died from signal " 00123 : " died for an obscure unknown reason with exit status ") 00124 << (WIFEXITED(rc) ? WEXITSTATUS(rc) 00125 : WIFSIGNALED(rc) ? WTERMSIG(rc) 00126 : rc); 00127 } 00128 }
int RemoteFile::local | ( | const std::string & | tmpdir, | |
std::string & | temp | |||
) | [static] |
Definition at line 49 of file RemoteFile.cc.
References IOChannel::fd(), len, mkstemp(), and throwStorageError().
Referenced by HttpStorageMaker::open(), and GsiFTPStorageMaker::open().
00050 { 00051 // Download temporary files to the current directory by default. 00052 // This is better for grid jobs as the current directory is 00053 // likely to have more space, and is more optimised for 00054 // large files, and is cleaned up after the job. 00055 if (tmpdir.empty () || tmpdir == ".") 00056 { 00057 size_t len = pathconf (".", _PC_PATH_MAX); 00058 char *buf = (char *) malloc (len); 00059 getcwd (buf, len); 00060 00061 temp.reserve (len + 32); 00062 temp = buf; 00063 free (buf); 00064 } 00065 else 00066 { 00067 temp.reserve (tmpdir.size() + 32); 00068 temp = tmpdir; 00069 } 00070 if (temp[temp.size()-1] != '/') 00071 temp += '/'; 00072 00073 temp += "storage-factory-local-XXXXXX"; 00074 temp.c_str(); // null terminate for mkstemp 00075 00076 int fd = mkstemp (&temp[0]); 00077 if (fd == -1) 00078 throwStorageError("RemoteFile::local()", "mkstemp()", errno); 00079 00080 return fd; 00081 }
std::string RemoteFile::name_ [private] |