diff --git a/GenericIO.cxx b/GenericIO.cxx index 83702c3c2cedbfbd547be1b29de5fc67f0b14fab..1912a48b4af20e6c44a6f18d66a74af2122e843d 100644 --- a/GenericIO.cxx +++ b/GenericIO.cxx @@ -84,10 +84,11 @@ GenericFileIO_MPI::~GenericFileIO_MPI() { (void) MPI_File_close(&FH); } -void GenericFileIO_MPI::open(const std::string &FN, bool ForReading) { +void GenericFileIO_MPI::open(const std::string &FN, bool ForReading, bool MustExist) { FileName = FN; - int amode = ForReading ? MPI_MODE_RDONLY : (MPI_MODE_WRONLY | MPI_MODE_CREATE); + int amode = ForReading ? MPI_MODE_RDONLY : (MPI_MODE_WRONLY | + (!MustExist ? MPI_MODE_CREATE : 0)); if (MPI_File_open(Comm, const_cast<char *>(FileName.c_str()), amode, MPI_INFO_NULL, &FH) != MPI_SUCCESS) throw runtime_error((!ForReading ? "Unable to create the file: " : @@ -183,10 +184,11 @@ GenericFileIO_POSIX::~GenericFileIO_POSIX() { if (FH != -1) close(FH); } -void GenericFileIO_POSIX::open(const std::string &FN, bool ForReading) { +void GenericFileIO_POSIX::open(const std::string &FN, bool ForReading, bool MustExist) { FileName = FN; - int flags = ForReading ? O_RDONLY : (O_WRONLY | O_CREAT); + int flags = ForReading ? O_RDONLY : (O_WRONLY | + (!MustExist ? O_CREAT : 0)); int mode = S_IRUSR | S_IWUSR | S_IRGRP; errno = 0; if ((FH = ::open(FileName.c_str(), flags, mode)) == -1) @@ -784,7 +786,7 @@ nocomp: else FH.get() = new GenericFileIO_POSIX(); - FH.get()->open(LocalFileName); + FH.get()->open(LocalFileName, false, true); uint64_t Offset = RHLocal.Start; for (size_t i = 0; i < Vars.size(); ++i) { diff --git a/GenericIO.h b/GenericIO.h index ce14f592113811b7447d830155ff7cb69f7705d1..cfb37b16ddd3b5ccea91b2d5b55392c56a8740cb 100644 --- a/GenericIO.h +++ b/GenericIO.h @@ -64,7 +64,7 @@ public: virtual ~GenericFileIO() {} public: - virtual void open(const std::string &FN, bool ForReading = false) = 0; + virtual void open(const std::string &FN, bool ForReading = false, bool MustExist = false) = 0; virtual void setSize(size_t sz) = 0; virtual void read(void *buf, size_t count, off_t offset, const std::string &D) = 0; @@ -82,7 +82,7 @@ public: virtual ~GenericFileIO_MPI(); public: - virtual void open(const std::string &FN, bool ForReading = false); + virtual void open(const std::string &FN, bool ForReading = false, bool MustExist = false); virtual void setSize(size_t sz); virtual void read(void *buf, size_t count, off_t offset, const std::string &D); virtual void write(const void *buf, size_t count, off_t offset, const std::string &D); @@ -108,7 +108,7 @@ public: ~GenericFileIO_POSIX(); public: - void open(const std::string &FN, bool ForReading = false); + void open(const std::string &FN, bool ForReading = false, bool MustExist = false); void setSize(size_t sz); void read(void *buf, size_t count, off_t offset, const std::string &D); void write(const void *buf, size_t count, off_t offset, const std::string &D);