diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 475c5ca41c9..3beea79f419 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -3109,11 +3109,12 @@ static RPCHelpMan dumptxoutset() const ArgsManager& args{EnsureAnyArgsman(request.context)}; const fs::path path = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(self.Arg("path"))); + const auto path_info{fs::status(path)}; // Write to a temporary path and then move into `path` on completion - // to avoid confusion due to an interruption. - const fs::path temppath = path + ".incomplete"; + // to avoid confusion due to an interruption. If a named pipe passed, write directly to it. + const fs::path temppath = fs::is_fifo(path_info) ? path : path + ".incomplete"; - if (fs::exists(path)) { + if (fs::exists(path_info) && !fs::is_fifo(path_info)) { throw JSONRPCError( RPC_INVALID_PARAMETER, path.utf8string() + " already exists. If you are sure this is what you want, " @@ -3197,7 +3198,9 @@ static RPCHelpMan dumptxoutset() path, temppath, node.rpc_interruption_point); - fs::rename(temppath, path); + if (!fs::is_fifo(path_info)) { + fs::rename(temppath, path); + } result.pushKV("path", path.utf8string()); return result; diff --git a/src/util/fs.h b/src/util/fs.h index 147904d030a..dce371cc5ef 100644 --- a/src/util/fs.h +++ b/src/util/fs.h @@ -96,6 +96,10 @@ static inline bool exists(const path& p) { return std::filesystem::exists(p); } +static inline bool exists(const std::filesystem::file_status& s) +{ + return std::filesystem::exists(s); +} // Allow explicit quoted stream I/O. static inline auto quoted(const std::string& s)