diff --git a/vrs/DiskFile.cpp b/vrs/DiskFile.cpp index 1e6b9f84..f0465f2a 100644 --- a/vrs/DiskFile.cpp +++ b/vrs/DiskFile.cpp @@ -99,9 +99,10 @@ bool DiskFile::isOpened() const { return currentChunk_ != nullptr; } -int DiskFile::create(const string& newFilePath) { +int DiskFile::create(const string& newFilePath, const map& options) { close(); readOnly_ = false; + options_ = options; return addChunk(newFilePath); } @@ -556,9 +557,9 @@ AtomicDiskFile::~AtomicDiskFile() { AtomicDiskFile::close(); // overrides not available in constructors & destructors } -int AtomicDiskFile::create(const std::string& newFilePath) { +int AtomicDiskFile::create(const std::string& newFilePath, const map& options) { finalName_ = newFilePath; - return DiskFile::create(os::getUniquePath(finalName_, 10)); + return DiskFile::create(os::getUniquePath(finalName_, 10), options); } int AtomicDiskFile::close() { diff --git a/vrs/DiskFile.h b/vrs/DiskFile.h index 17ef49e9..db76fcc5 100644 --- a/vrs/DiskFile.h +++ b/vrs/DiskFile.h @@ -46,7 +46,7 @@ class DiskFile : public WriteFileHandler { bool isOpened() const override; /// Create a new file - int create(const string& newFilePath) override; + int create(const string& newFilePath, const map& options = {}) override; /// Call this method to forget any chunk beyond this file size. void forgetFurtherChunks(int64_t fileSize) override; /// Get the total size of all the chunks considered. @@ -158,7 +158,7 @@ class DiskFile : public WriteFileHandler { } bool trySetPosInCurrentChunk(int64_t offset); - map options_; // optional options provided in openSpec + map options_; // optional options provided in openSpec or createFile vector chunks_; // all the chunks, when a VRS file is opened. DiskFileChunk* currentChunk_{}; // always points to the current chunk within chunks_. int filesOpenCount_{}; @@ -187,7 +187,7 @@ class AtomicDiskFile : public DiskFile { public: ~AtomicDiskFile() override; - int create(const string& newFilePath) override; + int create(const string& newFilePath, const map& options = {}) override; int close() override; void abort(); diff --git a/vrs/WriteFileHandler.h b/vrs/WriteFileHandler.h index 0eaf2c5f..ce64bc4c 100644 --- a/vrs/WriteFileHandler.h +++ b/vrs/WriteFileHandler.h @@ -48,13 +48,14 @@ class WriteFileHandler : public FileHandler { /// The path of the file to create is expected to be in the first chunk. /// Optional URI parameters might be provided in the spec' extras. virtual int create(const FileSpec& spec) { - return spec.chunks.empty() ? INVALID_FILE_SPEC : create(spec.chunks.front()); + return spec.chunks.empty() ? INVALID_FILE_SPEC : create(spec.chunks.front(), spec.extras); } /// Create a new file for writing. /// @param newFilePath: a disk path to create the file. + /// @param options: optional parameters to pass when creating the file. /// @return A status code, 0 meaning success. - virtual int create(const string& newFilePath) = 0; + virtual int create(const string& newFilePath, const map& options = {}) = 0; /// Create a new file for writing, in split-head file mode, the body part. /// @param spec: spec as converted already from initialFilePath, if that helps. @@ -63,9 +64,9 @@ class WriteFileHandler : public FileHandler { virtual int createSplitFile(const FileSpec& spec, const string& initialFilePath) { // create the (first) user record chunk if (spec.chunks.size() == 1) { - return create(spec.chunks.front() + "_1"); + return create(spec.chunks.front() + "_1", spec.extras); } else { - return create(initialFilePath); + return create(initialFilePath, spec.extras); } } diff --git a/vrs/test/file_tests/UserRecordsFileHandlerTest.cpp b/vrs/test/file_tests/UserRecordsFileHandlerTest.cpp index e96d2527..6ae32387 100644 --- a/vrs/test/file_tests/UserRecordsFileHandlerTest.cpp +++ b/vrs/test/file_tests/UserRecordsFileHandlerTest.cpp @@ -53,7 +53,7 @@ class UserRecordsFileHandler : public WriteFileHandler { /// Minimal implementations needed for a custom WriteFileHandler used for data writes only /// It can only write forward, no seek operations, no read back - int create(const string& newFilePath) override { + int create(const string& newFilePath, const map& /* options = {} */) override { if (file_ != nullptr) { return FILE_ALREADY_OPEN; }