]> gitweb.factorcode.org Git - factor.git/commitdiff
wipe: fix remove-read-only to be a HOOK: on windows, use ``random-file``
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 23 Aug 2023 15:49:40 +0000 (08:49 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 23 Aug 2023 15:49:40 +0000 (08:49 -0700)
extra/wipe/windows/windows.factor
extra/wipe/wipe.factor

index 5f06f1b65f302aa3f529e6c90b292574d25e9e55..1f30c4349020467c527ed9e5c9b46c8a0d69c04e 100644 (file)
@@ -6,6 +6,6 @@ IN: wipe.windows
 : extract-bit ( n mask -- n' ? )
     [ bitnot bitand ] [ bitand 0 = not ] bi-curry bi ; inline
 
-: remove-read-only ( file-name -- )
+M: windows remove-read-only
     dup GetFileAttributesW FILE_ATTRIBUTE_READONLY extract-bit
     [ set-file-attributes ] [ 2drop ] if ;
index 83957c005e5d9382433b5ade229d738ffac7246f..3ef628f1540167154d4e75a190e54e78fc42fefd 100644 (file)
@@ -1,23 +1,19 @@
 ! Copyright (C) 2017-2019, 2023 Alexander Ilin.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: accessors
-io io.directories io.encodings.binary io.files io.files.info
-io.files.unique io.streams.limited io.streams.random
-kernel math namespaces random system vocabs ;
+USING: accessors io io.directories io.encodings.binary io.files
+io.files.info io.files.unique io.streams.limited
+io.streams.random kernel namespaces system vocabs ;
 IN: wipe
 
-: remove-read-only ( file-name -- )
-    drop ; ! Do nothing by default.
+HOOK: remove-read-only os ( file-name -- )
+
+M: object remove-read-only drop ;
 
 ! Load a Windows-specific implementation of remove-read-only.
 os windows? [ "wipe.windows" require ] when
 
 : overwrite-with-random-bytes ( file-name -- )
-    [ remove-read-only ] [ file-info size>> ] [ ] tri binary [
-        <random-stream> swap limit-stream
-        0 seek-absolute output-stream get
-        [ stream-seek ] keep stream-copy
-    ] with-file-appender ;
+    [ remove-read-only ] [ file-info size>> ] [ random-file ] tri ;
 
 : make-file-empty ( file-name -- )
     binary [ ] with-file-writer ;