]> gitweb.factorcode.org Git - factor.git/commitdiff
io.directories: adding ?move-file
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 24 Aug 2023 16:54:34 +0000 (09:54 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 24 Aug 2023 16:54:34 +0000 (09:54 -0700)
basis/io/directories/directories-docs.factor
basis/io/directories/directories.factor
basis/logging/server/server.factor

index ffe6747c99295c12ebcff1063e2bc345ae95a3f5..2c7180776cb09ee92547decabdb9dbd4e802ef7e 100644 (file)
@@ -82,6 +82,10 @@ HELP: delete-file
 { $description "Deletes a file." }
 { $errors "Throws an error if the file could not be deleted." } ;
 
+HELP: ?delete-file
+{ $values { "path" "a pathname string" } }
+{ $description "Calls " { $link delete-file } " if the " { $snippet "path" } " file exists." } ;
+
 HELP: make-directory
 { $values { "path" "a pathname string" } }
 { $description "Creates a directory." }
@@ -113,6 +117,10 @@ HELP: move-file
 { $errors "Throws an error if the file does not exist or if the move operation fails." }
 { $see-also move-file-atomically } ;
 
+HELP: ?move-file
+{ $values { "from" "a pathname string" } { "to" "a pathname string" } }
+{ $description "Calls " { $link move-file } " if the " { $snippet "from" } " file exists." } ;
+
 HELP: move-file-atomically
 { $values { "from" "a pathname string" } { "to" "a pathname string" } }
 { $description "Moves or renames a file as an atomic operation." }
index b5ea21f909a0d7dda05c5c3ff19e53bc6417a590..be5af4e064a6a0926ab6cab7fcc34da74c6d5b13 100644 (file)
@@ -215,6 +215,9 @@ HOOK: delete-directory io-backend ( path -- )
 
 HOOK: move-file io-backend ( from to -- )
 
+: ?move-file ( from to -- )
+    over file-exists? [ move-file ] [ 2drop ] if ;
+
 HOOK: move-file-atomically io-backend ( from to -- )
 
 : move-file-into ( from to -- )
index 683c4ec804782a4b746024771f0429453b66d5bd..ab5c43044ee229c038d1285b1b45ad38828b8752 100644 (file)
@@ -70,9 +70,6 @@ CONSTANT: keep-logs 10
 : delete-oldest ( service -- )
     keep-logs log# ?delete-file ;
 
-: ?move-file ( old new -- )
-    over file-exists? [ move-file ] [ 2drop ] if ;
-
 : advance-log ( path n -- )
     [ 1 - log# ] 2keep log# ?move-file ;