Flush file before renaming

Previously s3fs could copy the zero-byte stub object without including
any pending writes.  Fixes #145.
This commit is contained in:
Andrew Gaul 2019-01-17 11:55:27 -08:00
parent 25b49e1a2e
commit 6401b4ae92
2 changed files with 8 additions and 2 deletions

View File

@ -1471,6 +1471,7 @@ static int rename_directory(const char* from, const char* to)
// does a safe copy - copies first and then deletes old
for(mn_cur = mn_head; mn_cur; mn_cur = mn_cur->next){
if(!mn_cur->is_dir){
// TODO: call s3fs_rename instead?
if(!nocopyapi && !norenameapi){
result = rename_object(mn_cur->old_path, mn_cur->new_path);
}else{
@ -1523,6 +1524,12 @@ static int s3fs_rename(const char* from, const char* to)
return result;
}
// flush pending writes if file is open
FdEntity *entity = FdManager::get()->ExistOpen(from);
if(entity != NULL){
entity->Flush(true);
}
// files larger than 5GB must be modified via the multipart interface
if(S_ISDIR(buf.st_mode)){
result = rename_directory(from, to);

View File

@ -500,8 +500,7 @@ function add_all_tests {
add_tests test_chown
add_tests test_list
add_tests test_remove_nonempty_directory
# TODO: broken: https://github.com/s3fs-fuse/s3fs-fuse/issues/145
#add_tests test_rename_before_close
add_tests test_rename_before_close
add_tests test_multipart_upload
add_tests test_multipart_copy
add_tests test_special_characters