Skip to content

Commit

Permalink
io.files.unique: fix stack effect, add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed May 29, 2024
1 parent adc4630 commit deb820d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions basis/io/files/unique/unique-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ tools.test unicode ;
"foo" utf8 file-contents
] with-temp-directory
] unit-test

{ "hello" } [
[
"hello" "foo"
[ utf8 set-file-contents ] safe-overwrite-file
"foo" utf8 file-contents
] with-temp-directory
] unit-test
4 changes: 2 additions & 2 deletions basis/io/files/unique/unique.factor
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ PRIVATE>
prefix suffixes unique-files :> paths
[ paths quot call ] [ paths [ ?delete-file ] each ] finally ; inline

: safe-overwrite-file ( ... original-path quot: ( ... empty-path -- ... ) -- ... )
: safe-overwrite-file ( ..a original-path quot: ( ..a empty-path -- ..b ) -- ..b )
[ "" "" ] dip '[
[ nip @ ] [ swap move-file-atomically ] 2bi
] cleanup-unique-file ; inline

: safe-replace-file ( ... original-path quot: ( ... copy-path -- ... ) -- ... )
: safe-replace-file ( ..a original-path quot: ( ..a copy-path -- ..b ) -- ..b )
[ "" "" ] dip '[
[ copy-file ] [ nip @ ] [ swap move-file-atomically ] 2tri
] cleanup-unique-file ; inline
Expand Down

0 comments on commit deb820d

Please sign in to comment.