test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
RemoteFile Class Reference

#include <RemoteFile.h>

Inheritance diagram for RemoteFile:
File IOChannel Storage IOInput IOOutput IOInput IOOutput

Public Member Functions

 ~RemoteFile (void)
 

Static Public Member Functions

static Storageget (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)
 
- Protected Member Functions inherited from File
virtual void attach (IOFD fd)
 
virtual void create (const char *name, bool exclusive=false, int perms=0666)
 
virtual void create (const std::string &name, bool exclusive=false, int perms=0666)
 
 File (void)
 
 File (IOFD fd, bool autoclose=true)
 
 File (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 File (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void flush (void)
 
virtual void open (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual IOOffset position (IOOffset offset, Relative whence=SET)
 
virtual bool prefetch (const IOPosBuffer *what, IOSize n)
 
virtual IOSize read (void *into, IOSize n)
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
virtual IOSize readv (IOBuffer *into, IOSize length)
 
virtual void resize (IOOffset size)
 
virtual void setAutoClose (bool closeit)
 
virtual IOOffset size (void) const
 
virtual IOSize write (const void *from, IOSize n)
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
virtual IOSize writev (const IOBuffer *from, IOSize length)
 
 ~File (void)
 
- Protected Member Functions inherited from IOChannel
bool sysclose (IOFD fd, int *error=0)
 
virtual IOFD fd (void) const
 
virtual void fd (IOFD value)
 
 IOChannel (IOFD fd=-1)
 
virtual bool isBlocking (void) const
 
virtual void setBlocking (bool value)
 
virtual ~IOChannel (void)
 
- Protected Member Functions inherited from IOInput
int read (void)
 
IOSize read (IOBuffer into)
 
IOSize xread (IOBuffer into)
 
IOSize xread (void *into, IOSize n)
 
IOSize xreadv (IOBuffer *into, IOSize buffers)
 
virtual ~IOInput (void)
 Destruct the stream. A no-op. More...
 
- Protected Member Functions inherited from IOOutput
IOSize write (unsigned char byte)
 
IOSize write (IOBuffer from)
 
IOSize xwrite (const void *from, IOSize n)
 
IOSize xwrite (IOBuffer from)
 
IOSize xwritev (const IOBuffer *from, IOSize buffers)
 
virtual ~IOOutput (void)
 Destruct the stream. A no-op. More...
 
- Protected Member Functions inherited from Storage
virtual bool eof (void) const
 
virtual IOOffset position (void) const
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void rewind (void)
 
 Storage (void)
 
IOSize write (IOBuffer from, IOOffset pos)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
virtual ~Storage (void)
 

Private Member Functions

 RemoteFile (IOFD fd, const std::string &name)
 
void remove (void)
 

Private Attributes

std::string name_
 

Detailed Description

Definition at line 7 of file RemoteFile.h.

Constructor & Destructor Documentation

RemoteFile::~RemoteFile ( void  )
inline

Definition at line 10 of file RemoteFile.h.

10 { remove (); }
RemoteFile::RemoteFile ( IOFD  fd,
const std::string &  name 
)
private

Definition at line 37 of file RemoteFile.cc.

Referenced by get().

38  : File (fd),
39  name_ (name)
40 {}
File(void)
Definition: File.cc:57
std::string name_
Definition: RemoteFile.h:23
virtual IOFD fd(void) const
Definition: IOChannel.cc:73

Member Function Documentation

void RemoteFile::abort ( void  )
protectedvirtual

Close the file and ignore all errors.

Reimplemented from File.

Definition at line 51 of file RemoteFile.cc.

References File::abort().

52 { remove(); File::abort (); }
virtual void abort(void)
Definition: File.cc:293
void RemoteFile::close ( void  )
protectedvirtual

Close the file.

Reimplemented from File.

Definition at line 47 of file RemoteFile.cc.

References File::close().

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), get(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

48 { remove(); File::close (); }
virtual void close(void)
Definition: File.cc:277
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, sysUtil::pid, RemoteFile(), and throwStorageError().

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), GsiFTPStorageMaker::open(), and HttpStorageMaker::open().

91 {
92  // FIXME: On write, create a temporary local file open for write;
93  // on close, trigger transfer to destination. If opening existing
94  // file for write, may need to first download.
95  assert (! (mode & (IOFlags::OpenWrite | IOFlags::OpenCreate)));
96 
97  pid_t pid = -1;
98  int rc = posix_spawnp (&pid, cmd[0], 0, 0, cmd, environ);
99 
100  if (rc == -1)
101  {
102  int errsave = errno;
103  ::close (localfd);
104  unlink (name.c_str());
105  throwStorageError ("RemoteFile", "Calling RemoteFile::get()", "posix_spawnp()", errsave);
106  }
107 
108  pid_t rcpid;
109  do
110  rcpid = waitpid(pid, &rc, 0);
111  while (rcpid == (pid_t) -1 && errno == EINTR);
112 
113  if (rcpid == (pid_t) -1)
114  {
115  int errsave = errno;
116  ::close (localfd);
117  unlink (name.c_str());
118  throwStorageError ("RemoteFile", "Calling RemoteFile::get()", "waitpid()", errsave);
119  }
120 
121  if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0)
122  return new RemoteFile (localfd, name);
123  else
124  {
125  ::close (localfd);
126  unlink (name.c_str());
127  cms::Exception ex("RemoteFile");
128  ex << "'" << join(cmd) << "'"
129  << (WIFEXITED(rc) ? " exited with exit code "
130  : WIFSIGNALED(rc) ? " died from signal "
131  : " died for an obscure unknown reason with exit status ")
132  << (WIFEXITED(rc) ? WEXITSTATUS(rc)
133  : WIFSIGNALED(rc) ? WTERMSIG(rc)
134  : rc);
135  ex.addContext("Calling RemoteFile::get()");
136  throw ex;
137  }
138 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
RemoteFile(IOFD fd, const std::string &name)
Definition: RemoteFile.cc:37
virtual void close(void)
Definition: RemoteFile.cc:47
string cmd
Definition: asciidump.py:19
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
tuple pid
Definition: sysUtil.py:22
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 GsiFTPStorageMaker::open(), and HttpStorageMaker::open().

56 {
57  // Download temporary files to the current directory by default.
58  // This is better for grid jobs as the current directory is
59  // likely to have more space, and is more optimised for
60  // large files, and is cleaned up after the job.
61  if (tmpdir.empty () || tmpdir == ".")
62  {
63  size_t len = pathconf (".", _PC_PATH_MAX);
64  char *buf = (char *) malloc (len);
65  getcwd (buf, len);
66 
67  temp.reserve (len + 32);
68  temp = buf;
69  free (buf);
70  }
71  else
72  {
73  temp.reserve (tmpdir.size() + 32);
74  temp = tmpdir;
75  }
76  if (temp[temp.size()-1] != '/')
77  temp += '/';
78 
79  temp += "storage-factory-local-XXXXXX";
80  temp.c_str(); // null terminate for mkstemp
81 
82  int fd = mkstemp (&temp[0]);
83  if (fd == -1)
84  throwStorageError("RemoteFile", "Calling RemoteFile::local()", "mkstemp()", errno);
85 
86  return fd;
87 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void RemoteFile::remove ( void  )
private

Definition at line 43 of file RemoteFile.cc.

References name_.

44 { unlink (name_.c_str()); }
std::string name_
Definition: RemoteFile.h:23

Member Data Documentation

std::string RemoteFile::name_
private

Definition at line 23 of file RemoteFile.h.

Referenced by remove().