Skip to content

Commit db88727

Browse files
committed
Added error code LFS_ERR_NOTEMPTY
As noted by itayzafrir, removing a non-empty directory should error with ENOTEMPTY, not EINVAL
1 parent c2fab8f commit db88727

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

lfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ int lfs_remove(lfs_t *lfs, const char *path) {
17401740
if (err) {
17411741
return err;
17421742
} else if (dir.d.size != sizeof(dir.d)+4) {
1743-
return LFS_ERR_INVAL;
1743+
return LFS_ERR_NOTEMPTY;
17441744
}
17451745
}
17461746

lfs.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ typedef uint32_t lfs_block_t;
4141
// Possible error codes, these are negative to allow
4242
// valid positive return values
4343
enum lfs_error {
44-
LFS_ERR_OK = 0, // No error
45-
LFS_ERR_IO = -5, // Error during device operation
46-
LFS_ERR_CORRUPT = -52, // Corrupted
47-
LFS_ERR_NOENT = -2, // No directory entry
48-
LFS_ERR_EXIST = -17, // Entry already exists
49-
LFS_ERR_NOTDIR = -20, // Entry is not a dir
50-
LFS_ERR_ISDIR = -21, // Entry is a dir
51-
LFS_ERR_INVAL = -22, // Invalid parameter
52-
LFS_ERR_NOSPC = -28, // No space left on device
53-
LFS_ERR_NOMEM = -12, // No more memory available
44+
LFS_ERR_OK = 0, // No error
45+
LFS_ERR_IO = -5, // Error during device operation
46+
LFS_ERR_CORRUPT = -52, // Corrupted
47+
LFS_ERR_NOENT = -2, // No directory entry
48+
LFS_ERR_EXIST = -17, // Entry already exists
49+
LFS_ERR_NOTDIR = -20, // Entry is not a dir
50+
LFS_ERR_ISDIR = -21, // Entry is a dir
51+
LFS_ERR_NOTEMPTY = -39, // Dir is not empty
52+
LFS_ERR_INVAL = -22, // Invalid parameter
53+
LFS_ERR_NOSPC = -28, // No space left on device
54+
LFS_ERR_NOMEM = -12, // No more memory available
5455
};
5556

5657
// File types

tests/test_dirs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ TEST
126126
echo "--- Directory remove ---"
127127
tests/test.py << TEST
128128
lfs_mount(&lfs, &cfg) => 0;
129-
lfs_remove(&lfs, "potato") => LFS_ERR_INVAL;
129+
lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY;
130130
lfs_remove(&lfs, "potato/sweet") => 0;
131131
lfs_remove(&lfs, "potato/baked") => 0;
132132
lfs_remove(&lfs, "potato/fried") => 0;
@@ -255,7 +255,7 @@ tests/test.py << TEST
255255
lfs_rename(&lfs, "warmpotato/baked", "coldpotato/baked") => 0;
256256
lfs_rename(&lfs, "warmpotato/sweet", "coldpotato/sweet") => 0;
257257
lfs_rename(&lfs, "warmpotato/fried", "coldpotato/fried") => 0;
258-
lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL;
258+
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
259259
lfs_remove(&lfs, "warmpotato") => 0;
260260
lfs_unmount(&lfs) => 0;
261261
TEST
@@ -285,7 +285,7 @@ TEST
285285
echo "--- Recursive remove ---"
286286
tests/test.py << TEST
287287
lfs_mount(&lfs, &cfg) => 0;
288-
lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL;
288+
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
289289
290290
lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0;
291291
lfs_dir_read(&lfs, &dir[0], &info) => 1;
@@ -328,7 +328,7 @@ TEST
328328
echo "--- Multi-block remove ---"
329329
tests/test.py << TEST
330330
lfs_mount(&lfs, &cfg) => 0;
331-
lfs_remove(&lfs, "cactus") => LFS_ERR_INVAL;
331+
lfs_remove(&lfs, "cactus") => LFS_ERR_NOTEMPTY;
332332
333333
for (int i = 0; i < $LARGESIZE; i++) {
334334
sprintf((char*)buffer, "cactus/test%d", i);

0 commit comments

Comments
 (0)