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 intospf13:masterfrom
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 |
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.