pathlocks.hh 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "types.hh"
  3. namespace nix {
  4. /* Open (possibly create) a lock file and return the file descriptor.
  5. -1 is returned if create is false and the lock could not be opened
  6. because it doesn't exist. Any other error throws an exception. */
  7. int openLockFile(const Path & path, bool create);
  8. /* Delete an open lock file. */
  9. void deleteLockFile(const Path & path, int fd);
  10. enum LockType { ltRead, ltWrite, ltNone };
  11. bool lockFile(int fd, LockType lockType, bool wait);
  12. class PathLocks
  13. {
  14. private:
  15. typedef std::pair<int, Path> FDPair;
  16. list<FDPair> fds;
  17. bool deletePaths;
  18. public:
  19. PathLocks();
  20. PathLocks(const PathSet & paths,
  21. const string & waitMsg = "");
  22. bool lockPaths(const PathSet & _paths,
  23. const string & waitMsg = "",
  24. bool wait = true);
  25. ~PathLocks();
  26. void unlock();
  27. void setDeletion(bool deletePaths);
  28. };
  29. bool pathIsLockedByMe(const Path & path);
  30. }