From 583f2580508a64debb567194c74f86383e476cc0 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Tue, 10 Oct 2023 10:21:44 -0700 Subject: [PATCH] Delegate VRS split file creation handling to WriteFileHandler Summary: Let the WriteFileHandler handle the creation of split file's file body, and avoid re-parsing the upload path as FileSpec. Reviewed By: kiminoue7 Differential Revision: D50109311 fbshipit-source-id: 9afcba792fc60404b1a38866016f67af452aae1a --- vrs/RecordFileWriter.cpp | 7 +------ vrs/WriteFileHandler.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/vrs/RecordFileWriter.cpp b/vrs/RecordFileWriter.cpp index 29ff276a..2c65aa12 100644 --- a/vrs/RecordFileWriter.cpp +++ b/vrs/RecordFileWriter.cpp @@ -854,12 +854,7 @@ int RecordFileWriter::createFile(const string& filePath, bool splitHead) { if (splitHead) { IF_ERROR_LOG_CLOSE_AND_RETURN(indexRecordWriter_.createSplitIndexRecord(lastRecordSize_)) - // create the (first) user record chunk - if (spec.chunks.size() == 1) { - IF_ERROR_LOG_CLOSE_AND_RETURN(file_->create(spec.chunks.front() + "_1")) - } else { - IF_ERROR_LOG_CLOSE_AND_RETURN(file_->create(filePath)) - } + IF_ERROR_LOG_CLOSE_AND_RETURN(file_->createSplitFile(spec, filePath)); } else if (preliminaryIndex_ && !preliminaryIndex_->empty()) { // only use this preliminary index once unique_ptr> index = std::move(preliminaryIndex_); diff --git a/vrs/WriteFileHandler.h b/vrs/WriteFileHandler.h index 8d99f6ba..91591759 100644 --- a/vrs/WriteFileHandler.h +++ b/vrs/WriteFileHandler.h @@ -46,6 +46,19 @@ class WriteFileHandler : public FileHandler { /// @return A status code, 0 meaning success. virtual int create(const string& newFilePath) = 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. + /// @param initialFilePath: path as given when the file creation was started. + /// @return A status code, 0 meaning success. + 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"); + } else { + return create(initialFilePath); + } + } + /// Tell if modifying files is supported by this FileHandler implementation. /// @return True if file modification and creation is supported. virtual bool reopenForUpdatesSupported() const = 0;