1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 13:06:01 +01:00

Create a wrapper around stdlib’s rename

Directly takes some c++ strings, and gently throws an exception on error
(rather than having to inline this logic everywhere)
This commit is contained in:
Théophane Hufschmitt 2022-03-17 15:28:46 +01:00 committed by Théophane Hufschmitt
parent 8119390abc
commit c2de0a232c
9 changed files with 22 additions and 22 deletions

View file

@ -34,11 +34,16 @@ void replaceSymlink(const Path & target, const Path & link,
throw;
}
if (rename(tmp.c_str(), link.c_str()) != 0)
throw SysError("renaming '%1%' to '%2%'", tmp, link);
moveFile(tmp, link);
break;
}
}
void moveFile(const Path & oldName, const Path & newName)
{
if (::rename(oldName.c_str(), newName.c_str()))
throw SysError("renaming '%1%' to '%2%'", oldName, newName);
}
}

View file

@ -168,6 +168,8 @@ void createSymlink(const Path & target, const Path & link,
void replaceSymlink(const Path & target, const Path & link,
std::optional<time_t> mtime = {});
void moveFile(const Path & src, const Path & dst);
/* Wrappers arount read()/write() that read/write exactly the
requested number of bytes. */