]> gitweb.factorcode.org Git - factor.git/commitdiff
io.files.trash.windows: convert input path to absolute in send-to-trash
authorAlexander Iljin <ajsoft@yandex.ru>
Mon, 30 Jul 2018 07:21:25 +0000 (09:21 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 17 Apr 2020 02:55:24 +0000 (02:55 +0000)
The input path must be absolute, but normalize-path can't be used, because
that returns UNC path, and SHFileOperation fails on any path prefixed with
"\\?", see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shfileopstructa
Use absolute-path instead. The mixture of slashes and backslashes in the
path is tolerated, at least on Windows 10.

Add a simple unit-test.

extra/io/files/trash/trash-tests.factor [new file with mode: 0644]
extra/io/files/trash/windows/windows.factor

diff --git a/extra/io/files/trash/trash-tests.factor b/extra/io/files/trash/trash-tests.factor
new file mode 100644 (file)
index 0000000..1c054d6
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2020 Alexander Ilin.
+! See http://factorcode.org/license.txt for BSD license.
+USING: io.directories io.files.trash kernel tools.test ;
+IN: io.files.trash.tests
+
+{ } [
+    ! temp-file is not used here, because it returns the absolute path, and we
+    ! want to ensure send-to-trash works without giving it the full path.
+    [ "io.files.trash-tests" dup touch-file send-to-trash ] with-test-directory
+] unit-test
index f1b0d9ab0ce10d880b0c1a93b3a5417e46a23a0d..bfae7e66ee0f49de61214932064ce85a7d0f9cbd 100644 (file)
@@ -2,8 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license
 
 USING: accessors alien.c-types alien.data alien.strings
-alien.syntax classes.struct destructors io.files.trash kernel
-libc literals math sequences system windows.types ;
+alien.syntax classes.struct destructors io.files.trash
+io.pathnames kernel libc literals math sequences system
+windows.types ;
 
 IN: io.files.trash.windows
 
@@ -51,7 +52,7 @@ PRIVATE>
 
 M: windows send-to-trash ( path -- )
     [
-        native-string>alien B{ 0 0 } append
+        absolute-path native-string>alien B{ 0 0 } append
         malloc-byte-array &free
 
         SHFILEOPSTRUCTW <struct>