Browse Source

Added error code LFS_ERR_NOTEMPTY

As noted by itayzafrir, removing a non-empty directory should
error with ENOTEMPTY, not EINVAL
Christopher Haster 8 năm trước cách đây
mục cha
commit
db8872781a
3 tập tin đã thay đổi với 16 bổ sung15 xóa
  1. 1 1
      lfs.c
  2. 11 10
      lfs.h
  3. 4 4
      tests/test_dirs.sh

+ 1 - 1
lfs.c

@@ -1740,7 +1740,7 @@ int lfs_remove(lfs_t *lfs, const char *path) {
         if (err) {
             return err;
         } else if (dir.d.size != sizeof(dir.d)+4) {
-            return LFS_ERR_INVAL;
+            return LFS_ERR_NOTEMPTY;
         }
     }
 

+ 11 - 10
lfs.h

@@ -41,16 +41,17 @@ typedef uint32_t lfs_block_t;
 // Possible error codes, these are negative to allow
 // valid positive return values
 enum lfs_error {
-    LFS_ERR_OK      = 0,    // No error
-    LFS_ERR_IO      = -5,   // Error during device operation
-    LFS_ERR_CORRUPT = -52,  // Corrupted
-    LFS_ERR_NOENT   = -2,   // No directory entry
-    LFS_ERR_EXIST   = -17,  // Entry already exists
-    LFS_ERR_NOTDIR  = -20,  // Entry is not a dir
-    LFS_ERR_ISDIR   = -21,  // Entry is a dir
-    LFS_ERR_INVAL   = -22,  // Invalid parameter
-    LFS_ERR_NOSPC   = -28,  // No space left on device
-    LFS_ERR_NOMEM   = -12,  // No more memory available
+    LFS_ERR_OK       = 0,    // No error
+    LFS_ERR_IO       = -5,   // Error during device operation
+    LFS_ERR_CORRUPT  = -52,  // Corrupted
+    LFS_ERR_NOENT    = -2,   // No directory entry
+    LFS_ERR_EXIST    = -17,  // Entry already exists
+    LFS_ERR_NOTDIR   = -20,  // Entry is not a dir
+    LFS_ERR_ISDIR    = -21,  // Entry is a dir
+    LFS_ERR_NOTEMPTY = -39,  // Dir is not empty
+    LFS_ERR_INVAL    = -22,  // Invalid parameter
+    LFS_ERR_NOSPC    = -28,  // No space left on device
+    LFS_ERR_NOMEM    = -12,  // No more memory available
 };
 
 // File types

+ 4 - 4
tests/test_dirs.sh

@@ -126,7 +126,7 @@ TEST
 echo "--- Directory remove ---"
 tests/test.py << TEST
     lfs_mount(&lfs, &cfg) => 0;
-    lfs_remove(&lfs, "potato") => LFS_ERR_INVAL;
+    lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY;
     lfs_remove(&lfs, "potato/sweet") => 0;
     lfs_remove(&lfs, "potato/baked") => 0;
     lfs_remove(&lfs, "potato/fried") => 0;
@@ -255,7 +255,7 @@ tests/test.py << TEST
     lfs_rename(&lfs, "warmpotato/baked", "coldpotato/baked") => 0;
     lfs_rename(&lfs, "warmpotato/sweet", "coldpotato/sweet") => 0;
     lfs_rename(&lfs, "warmpotato/fried", "coldpotato/fried") => 0;
-    lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL;
+    lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
     lfs_remove(&lfs, "warmpotato") => 0;
     lfs_unmount(&lfs) => 0;
 TEST
@@ -285,7 +285,7 @@ TEST
 echo "--- Recursive remove ---"
 tests/test.py << TEST
     lfs_mount(&lfs, &cfg) => 0;
-    lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL;
+    lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
 
     lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0;
     lfs_dir_read(&lfs, &dir[0], &info) => 1;
@@ -328,7 +328,7 @@ TEST
 echo "--- Multi-block remove ---"
 tests/test.py << TEST
     lfs_mount(&lfs, &cfg) => 0;
-    lfs_remove(&lfs, "cactus") => LFS_ERR_INVAL;
+    lfs_remove(&lfs, "cactus") => LFS_ERR_NOTEMPTY;
 
     for (int i = 0; i < $LARGESIZE; i++) {
         sprintf((char*)buffer, "cactus/test%d", i);