#include <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) |
virtual void | close (void) |
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] |
Definition at line 10 of file RemoteFile.h.
{ remove (); }
RemoteFile::RemoteFile | ( | IOFD | fd, |
const std::string & | name | ||
) | [private] |
void RemoteFile::abort | ( | void | ) | [protected, virtual] |
Close the file and ignore all errors.
Reimplemented from File.
Definition at line 51 of file RemoteFile.cc.
{ remove(); File::abort (); }
void RemoteFile::close | ( | void | ) | [protected, virtual] |
Close the file.
Reimplemented from File.
Definition at line 47 of file RemoteFile.cc.
Referenced by get().
{ remove(); File::close (); }
Storage * RemoteFile::get | ( | int | localfd, |
const std::string & | name, | ||
char ** | cmd, | ||
int | mode | ||
) | [static] |
Definition at line 90 of file RemoteFile.cc.
References close(), join(), IOFlags::OpenCreate, IOFlags::OpenWrite, evf::utils::pid, RemoteFile(), and throwStorageError().
{ // FIXME: On write, create a temporary local file open for write; // on close, trigger transfer to destination. If opening existing // file for write, may need to first download. assert (! (mode & (IOFlags::OpenWrite | IOFlags::OpenCreate))); pid_t pid = -1; int rc = posix_spawnp (&pid, cmd[0], 0, 0, cmd, environ); if (rc == -1) { int errsave = errno; ::close (localfd); unlink (name.c_str()); throwStorageError ("RemoteFile", "Calling RemoteFile::get()", "posix_spawnp()", errsave); } pid_t rcpid; do rcpid = waitpid(pid, &rc, 0); while (rcpid == (pid_t) -1 && errno == EINTR); if (rcpid == (pid_t) -1) { int errsave = errno; ::close (localfd); unlink (name.c_str()); throwStorageError ("RemoteFile", "Calling RemoteFile::get()", "waitpid()", errsave); } if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0) return new RemoteFile (localfd, name); else { ::close (localfd); unlink (name.c_str()); cms::Exception ex("RemoteFile"); ex << "'" << join(cmd) << "'" << (WIFEXITED(rc) ? " exited with exit code " : WIFSIGNALED(rc) ? " died from signal " : " died for an obscure unknown reason with exit status ") << (WIFEXITED(rc) ? WEXITSTATUS(rc) : WIFSIGNALED(rc) ? WTERMSIG(rc) : rc); ex.addContext("Calling RemoteFile::get()"); throw ex; } }
int RemoteFile::local | ( | const std::string & | tmpdir, |
std::string & | temp | ||
) | [static] |
Definition at line 55 of file RemoteFile.cc.
References IOChannel::fd(), and throwStorageError().
Referenced by HttpStorageMaker::open(), and GsiFTPStorageMaker::open().
{ // Download temporary files to the current directory by default. // This is better for grid jobs as the current directory is // likely to have more space, and is more optimised for // large files, and is cleaned up after the job. if (tmpdir.empty () || tmpdir == ".") { size_t len = pathconf (".", _PC_PATH_MAX); char *buf = (char *) malloc (len); getcwd (buf, len); temp.reserve (len + 32); temp = buf; free (buf); } else { temp.reserve (tmpdir.size() + 32); temp = tmpdir; } if (temp[temp.size()-1] != '/') temp += '/'; temp += "storage-factory-local-XXXXXX"; temp.c_str(); // null terminate for mkstemp int fd = mkstemp (&temp[0]); if (fd == -1) throwStorageError("RemoteFile", "Calling RemoteFile::local()", "mkstemp()", errno); return fd; }
void RemoteFile::remove | ( | void | ) | [private] |
std::string RemoteFile::name_ [private] |
Definition at line 23 of file RemoteFile.h.
Referenced by remove().