Skip to content

Conversation

@BlazingTwist
Copy link
Contributor

@BlazingTwist BlazingTwist commented Nov 5, 2025

BREAKING:

  • sys.file_exists was renamed to sys.isfile to match the existing sys.isdir instruction
  • sys.mvdir 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

Discussion: 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.mv and sys.cp with directory destinations might cause unpleasant surprises if you expect the behaviour of Linux' mv and cp.
E.g. "dir1" "dir2" :(sys.cp) replaces the potentially existing dir2 with a copy of dir1.
Personally I don't love that mv/cp dir1 dir2 behaves differently depending on whether dir2 exists, so I chose not to mirror that behaviour.

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
@nick-paul
Copy link
Collaborator

Thanks for these updates, I have a few questions:

  1. Is sys.mvdir just a subset of sys.mv that explicitly works on directories?

  2. Replacement behavior:

E.g. "dir1" "dir2" :(sys.cp) replaces the potentially existing dir2 with a copy of dir1.

I'm a bit concerned the replacement behavior could potentially cause confusion. We could try to mirror the linux behavior a bit closer (cp -r dir1 dir2 puts a copy of dir1 inside of dir2 -> dir2/dir1) but the easiest solution may be to disallow any destructive behavior if the second argument already exists. So if the user intended to replace dir2 with dir1, they would need to delete dir2 first and then run "dir1" "dir2" :(sys.cp). Or if the user intended to put a copy of dir1 inside dir2, then they would need to specify it: "dir1" "dir2/dir1" :(sys.cp).

@BlazingTwist
Copy link
Contributor Author

  1. Is sys.mvdir just a subset of sys.mv that explicitly works on directories?

Yes, sys.mvdir is now just sugar for a sys.isdir assert and sys.mv.
I figured I'd leave it intact, it was introduced here 63fd372

  1. Replacement behavior

I think disallowing destructive behaviour entirely is reasonable. Done.

I removed several of the tests as they are illegal now.

@nick-paul nick-paul merged commit f8a95d1 into aya-lang:master Dec 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants