Extend Filesystem Instructions#161
Conversation
BREAKING: - `sys.file_exists` was renamed to `sys.isfile` to match the existing `sys.isdir` instruction - `sys.mv_dir` now overwrites non-empty directories. Previously only empty directories were overwritten. Additions: - `sys.exists` to test if a file/directory exists - `sys.mv` to move files/directories - `sys.cp` to copy files/directories Fixes: - `fileutils.readallbytes` added missing doc-string
…xical operations.
|
Thanks for these updates, I have a few questions:
I'm a bit concerned the replacement behavior could potentially cause confusion. We could try to mirror the linux behavior a bit closer ( |
Yes,
I think disallowing destructive behaviour entirely is reasonable. Done. I removed several of the tests as they are illegal now. |
BREAKING:
sys.file_existswas renamed tosys.isfileto match the existingsys.isdirinstructionsys.mvdirnow overwrites non-empty directories. Previously only empty directories were overwritten.Additions:
sys.existsto test if a file/directory existssys.mvto move files/directoriessys.cpto copy files/directoriesFixes:
fileutils.readallbytesadded missing doc-stringDiscussion: Preventing Footguns
I have disabled the ability to copy folders into themselves. (e.g.
"dir" "dir/dir2" :(sys.cp))As well as files replacing their parents (e.g.
"dir" "./" :(sys.cp)would delete the current directory)The current behaviour of
sys.mvandsys.cpwith directory destinations might cause unpleasant surprises if you expect the behaviour of Linux'mvandcp.E.g.
"dir1" "dir2" :(sys.cp)replaces the potentially existingdir2with a copy ofdir1.Personally I don't love that
mv/cp dir1 dir2behaves differently depending on whetherdir2exists, so I chose not to mirror that behaviour.