hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit e65a3d7d11c9bb6a51ba3857ccf5f682a31d46b1
parent 887c7c8b6e038e7aa0470a6e33ac878b37ed29fb
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 22 Jun 2021 14:32:20 -0400

fs::move: implement copy+delete fallback

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mfs/fs.ha | 9++++++++-
Mos/+linux/dirfdfs.ha | 1+
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/fs.ha b/fs/fs.ha @@ -64,7 +64,14 @@ export fn move(fs: *fs, oldpath: str, newpath: str) (void | error) = { void => return, // Success err: error => return err, }; - abort(); // TODO: Fallback + // XXX: If an error occurs, remove the new file. + let st = fs::stat(fs, oldpath)?; + let new = fs::create(fs, newpath, st.mode)?; + defer io::close(new); + let old = fs::open(fs, oldpath)?; + defer io::close(old); + io::copy(new, old)?; + fs::remove(fs, oldpath)?; }; // Returns an iterator for a path, which yields the contents of a directory. diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -102,6 +102,7 @@ fn errno_to_fs(err: rt::errno) fs::error = switch (err) { rt::EBUSY => errors::busy, rt::ENOTDIR => fs::wrongtype, rt::EOPNOTSUPP, rt::ENOSYS => errors::unsupported, + rt::EXDEV => fs::cannotrename, * => errors::errno(err), };