Skip to content

Commit

Permalink
Add filesystem::delete_file
Browse files Browse the repository at this point in the history
  • Loading branch information
AI0867 committed Nov 27, 2013
1 parent 6f2c048 commit 342ee26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/filesystem.cpp
Expand Up @@ -346,6 +346,15 @@ bool delete_directory(const std::string& path, const bool keep_pbl)
}
return ret;
}
bool delete_file(const std::string& path)
{
bool ret = true;
if(remove(path.c_str()) != 0 && errno != ENOENT) {
ERR_FS << "remove(" << path << "): " << strerror(errno) << "\n";
ret = false;
}
return ret;
}

std::string get_cwd()
{
Expand Down
1 change: 1 addition & 0 deletions src/filesystem.hpp
Expand Up @@ -89,6 +89,7 @@ std::string get_exe_dir();

bool make_directory(const std::string& dirname);
bool delete_directory(const std::string& dirname, const bool keep_pbl = false);
bool delete_file(const std::string &filename);

bool looks_like_pbl(const std::string& file);

Expand Down
10 changes: 10 additions & 0 deletions src/filesystem_boost.cpp
Expand Up @@ -553,6 +553,16 @@ bool delete_directory(const std::string& dirname, const bool keep_pbl)
return ret;
}

bool delete_file(const std::string &filename)
{
error_code ec;
bool ret = bfs::remove(path(filename), ec);
if (ec) {
ERR_FS << "Could not delete file " << filename << ": " << ec.message() << '\n';
}
return ret;
}

std::string read_file(const std::string &fname)
{
scoped_istream is = istream_file(fname);
Expand Down

0 comments on commit 342ee26

Please sign in to comment.