janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.38k stars 217 forks source link

`os/rename` behaves differently on Linux vs Windows #1331

Closed CFiggers closed 7 months ago

CFiggers commented 7 months ago

It seems like on Linux, if a file is renamed using os/rename to a filename that already exists, it overwrites the existing file. On Windows, the same thing returns an error.

Linux:

Janet 1.32.1-cc5beda0 linux/x64/gcc - '(doc)' for help
repl:1:> (os/dir ".")
@["other" "thing"]
repl:2:> (os/rename "other" "thing")
nil
repl:3:> (os/dir ".")
@["thing"]

Windows:

Janet 1.32.1-local windows/x64/msvc - '(doc)' for help
repl:1:> (os/dir ".")
@["other" "thing"]
repl:2:> (os/rename "thing" "other")
error: File exists
  in os/rename [src/core/os.c] on line 2351
  in _thunk [repl] (tailcall) on line 2, column 1

Should the behavior of os/rename be the same on both platforms?

sogaiu commented 7 months ago

For reference, here is some info that mentions the difference in behavior of rename (which IIUC is what os/rename wraps) among some platforms.

bakpakin commented 7 months ago

Not going to fix this, there are many difference between various file systems that Janet cannot reasonably paper over in a nice way.