summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2010-01-01 20:41:29 +0000
committerAmaury Pouly <pamaury@rockbox.org>2010-01-01 20:41:29 +0000
commit839007872a4ae8d7fab58e877d9454a32540c08d (patch)
tree713d93157527f5a7ab932ac8d9cd0d6e7b31f207
parent2392bb41996963c6683253114bdfb3174146e7dc (diff)
downloadrockbox-839007872a4ae8d7fab58e877d9454a32540c08d.tar.gz
rockbox-839007872a4ae8d7fab58e877d9454a32540c08d.tar.bz2
rockbox-839007872a4ae8d7fab58e877d9454a32540c08d.zip
FS#9409: fix rename which didn't close file handles on error and enventually cause cut/paste to fail between volumes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24134 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/file.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index a80aed5396..7ec712a244 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -367,8 +367,10 @@ int rename(const char* path, const char* newpath)
nameptr = strrchr(newpath,'/');
if (nameptr)
nameptr++;
- else
+ else {
+ close(fd);
return - 3;
+ }
/* Extract new path */
strcpy(newpath2, newpath);
@@ -376,8 +378,10 @@ int rename(const char* path, const char* newpath)
dirptr = strrchr(newpath2,'/');
if(dirptr)
*dirptr = 0;
- else
+ else {
+ close(fd);
return - 4;
+ }
dirptr = newpath2;
@@ -386,8 +390,10 @@ int rename(const char* path, const char* newpath)
}
dir = opendir_uncached(dirptr);
- if(!dir)
+ if(!dir) {
+ close(fd);
return - 5;
+ }
file = &openfiles[fd];
@@ -395,12 +401,16 @@ int rename(const char* path, const char* newpath)
file->size, file->attr);
#ifdef HAVE_MULTIVOLUME
if ( rc == -1) {
+ close(fd);
+ closedir_uncached(dir);
DEBUGF("Failed renaming file across volumnes: %d\n", rc);
errno = EXDEV;
return -6;
}
#endif
if ( rc < 0 ) {
+ close(fd);
+ closedir_uncached(dir);
DEBUGF("Failed renaming file: %d\n", rc);
errno = EIO;
return rc * 10 - 7;
@@ -412,6 +422,7 @@ int rename(const char* path, const char* newpath)
rc = close(fd);
if (rc<0) {
+ closedir_uncached(dir);
errno = EIO;
return rc * 10 - 8;
}