fix: MemMapFs.Remove returns error for non-empty directories#587
fix: MemMapFs.Remove returns error for non-empty directories#587Yanhu007 wants to merge 1 commit into
Conversation
os.Remove on real filesystems returns ENOTEMPTY when removing a non-empty directory. MemMapFs.Remove silently removes the directory and all its contents, which violates the os.Remove contract. Add a check for child entries before removing a directory. If any children exist, return os.PathError with syscall.ENOTEMPTY. Fixes spf13#232
|
|
|
The prefix check |
|
@Yanhu007 the fix is correct and the downstream impact analysis looks good — we checked the major consumers and they all either pre-check emptiness or use RemoveAll for trees. Two things blocking merge:
The implementation (prefix scan, syscall.ENOTEMPTY, PathError wrapper) is correct as-is. |
|
The fix is correct — Before merging, we need to think through the impact:
The intent is right. The implementation needs the performance issue resolved, and we need to be deliberate about how we communicate this change to users. |
Fixes #232
Problem
MemMapFs.Remove()silently removes a non-empty directory and all its contents. This violates theos.Removecontract, which returnsENOTEMPTYfor non-empty directories.Fix
Before removing a directory, check if any entries have the directory path as a prefix. If children exist, return
&os.PathError{Op: "remove", Path: name, Err: syscall.ENOTEMPTY}.This matches the behavior of
os.Removeon real filesystems.