Skip to content

Commit

Permalink
[SAFS]: print err msgs when renaming fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
zheng-da committed Jun 30, 2016
1 parent f77a985 commit 8934a58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
15 changes: 15 additions & 0 deletions libsafs/native_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <stddef.h>
#include <assert.h>
#include <errno.h>
#include <string.h>

#include "common.h"
#include "native_file.h"
Expand Down Expand Up @@ -121,4 +123,17 @@ bool native_dir::delete_dir(bool recursive)
}
}

bool native_file::rename(const std::string &new_name)
{
if (::rename(file_name.c_str(), new_name.c_str()) == 0) {
file_name = new_name;
return true;
}
else {
fprintf(stderr, "can't renmae to %s: %s\n", new_name.c_str(),
strerror(errno));
return false;
}
}

}
9 changes: 1 addition & 8 deletions libsafs/native_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ class native_file
return file_name;
}

virtual bool rename(const std::string &new_name) {
if (::rename(file_name.c_str(), new_name.c_str()) == 0) {
file_name = new_name;
return true;
}
else
return false;
}
virtual bool rename(const std::string &new_name);

/**
* Create/delete a file on the native file system.
Expand Down
5 changes: 4 additions & 1 deletion libsafs/safs_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ ssize_t safs_file::get_size() const

bool safs_file::rename(const std::string &new_name)
{
if (!exist())
if (!exist()) {
fprintf(stderr, "can't rename: the new name %s exists\n",
new_name.c_str());
return false;
}

for (unsigned i = 0; i < native_dirs.size(); i++) {
native_file f(native_dirs[i].get_file_name());
Expand Down

0 comments on commit 8934a58

Please sign in to comment.