Page MenuHomePhabricator

Extend IO util by a method for temporary filenames without a stream
Closed, ResolvedPublic

Description

There already is a method which returns a temporary file, but it requires an input stream.

std::string CreateTemporaryFile(std::ofstream& tmpStream, std::ios_base::openmode mode, const std::string& templateName = "XXXXXX", std::string path = std::string());

Another method which doesn't need a stream would be helpful and save some lines of codes when a stream is not needed.

Event Timeline

New remote branch pushed: bug-16932-ExtendIOUtil

Please add the default arguments from the stream version of the CreateTemporaryFile() method for the sake of consistency. So we would need to versions:

static std::string CreateTemporaryFile(const std::string& templateName = "XXXXXX",

std::string path = std::string());

static std::string CreateTemporaryFile(std::ios_base::openmode mode,

const std::string& templateName = "XXXXXX",
std::string path = std::string());

The documentation would also need to be updated for the new arguments.

Thanks for your comments, changed this as proposed. Branch is now ready for merge.

Ah, there is one mistake. The second version isn't needed because the file is not kept open and users need to open it for reading/writing themselves and can supply open mode there. So we actually need just the first version.

Could you please also add the following comment to the documentation of the first version:


This version is potentially unsafe because the created temporary file is not kept open and could be used by another process between calling this method and opening the returned file path for reading or writing.

Thanks.

[12d06d]: Merge branch 'bug-16932-ExtendIOUtil'

Merged commits:

2014-02-05 15:01:46 Alfred Franz [6e942a]
removed method which is not needed (file open mode is not relevant if the file is closed immediately anyway)


2014-01-29 18:19:47 Alfred Franz [ad851f]
add the default arguments from the stream version of the CreateTemporaryFile() method


2014-01-29 16:49:00 Alfred Franz [7cac14]
added test for new method mitk::IOUtil::CreateTemporaryFile()


2014-01-22 15:21:45 Alfred Franz [0be8d0]
now using IOUtil to get temporary file name, this might avoid problems with file access.


2014-01-22 15:21:02 Alfred Franz [f18b31]
Added new method for creating an empty temporary file without a using stream.