From a06e9cc3b20ef78af220b8d0cb2da9bea8d01963 Mon Sep 17 00:00:00 2001 From: Alexander Iljin Date: Mon, 30 Jul 2018 09:21:25 +0200 Subject: [PATCH] io.files.trash.windows: convert input path to absolute in send-to-trash 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 | 10 ++++++++++ extra/io/files/trash/windows/windows.factor | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 extra/io/files/trash/trash-tests.factor diff --git a/extra/io/files/trash/trash-tests.factor b/extra/io/files/trash/trash-tests.factor new file mode 100644 index 0000000000..1c054d65be --- /dev/null +++ b/extra/io/files/trash/trash-tests.factor @@ -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 diff --git a/extra/io/files/trash/windows/windows.factor b/extra/io/files/trash/windows/windows.factor index f1b0d9ab0c..bfae7e66ee 100644 --- a/extra/io/files/trash/windows/windows.factor +++ b/extra/io/files/trash/windows/windows.factor @@ -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