dir-rename.lisp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (in-package :hurd-translator)
  2. (def-fs-interface :dir-rename ((old-dir port)
  3. (old-name :string)
  4. (new-dir port)
  5. (new-name :string)
  6. (excl :boolean))
  7. (with-lookup old-dir-protid old-dir
  8. (block dir-rename
  9. (unless (port-exists-p new-dir)
  10. (return-from dir-rename :invalid-cross-device-link))
  11. (with-lookup new-dir-protid new-dir
  12. (let* ((old-dir-node (get-node old-dir-protid))
  13. (old-dir-user (get-user old-dir-protid))
  14. (found-old-node (directory-lookup *translator*
  15. old-dir-node
  16. old-dir-user
  17. old-name)))
  18. (unless found-old-node
  19. (return-from dir-rename :no-such-file))
  20. (let* ((new-dir-node (get-node new-dir-protid))
  21. (new-dir-user (get-user new-dir-protid))
  22. (found-new-node (directory-lookup *translator*
  23. new-dir-node
  24. new-dir-user
  25. new-name)))
  26. (when (and found-new-node excl)
  27. (return-from dir-rename :file-exists))
  28. (let ((return-code (file-rename *translator*
  29. old-dir-user
  30. old-dir-node
  31. old-name
  32. new-dir-node
  33. new-name)))
  34. (when (eq t return-code)
  35. (deallocate-send-right new-dir-protid))
  36. (cond
  37. ((eq t return-code) t)
  38. ((eq nil return-code) :permission-denied)
  39. (t return-code)))))))))