io.files.windows: fix incorrect parsing of file attribute bitfield in win32-file-attributes

db4
Björn Lindqvist 2015-10-11 04:11:30 +02:00
parent e8841a4967
commit e35087fb22
3 changed files with 51 additions and 29 deletions

View File

@ -0,0 +1,20 @@
USING: accessors combinators io.directories io.files.temp
io.files.windows io.pathnames kernel math sequences tools.test
windows.kernel32 ;
IN: io.directories.windows.tests
{ { +read-only+ +archive+ } } [
"read-only.file" temp-file {
[ ?delete-file ]
[ touch-file ]
[
FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_ARCHIVE bitor
set-file-attributes
]
[
parent-directory (directory-entries)
[ name>> "read-only.file" = ] find nip
attributes>>
]
} cleave
] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2010 Doug Coleman. ! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io.files io.pathnames kernel tools.test io.backend USING: io.backend io.files io.files.windows io.pathnames kernel
io.files.windows splitting sequences io.pathnames.private ; sequences splitting tools.test ;
IN: io.files.windows.tests IN: io.files.windows.tests
[ f ] [ "\\foo" absolute-path? ] unit-test [ f ] [ "\\foo" absolute-path? ] unit-test
@ -58,3 +58,10 @@ IN: io.files.windows.tests
[ "c:\\blah" ] [ "c:\\foo\\bar" "\\blah" append-path ] unit-test [ "c:\\blah" ] [ "c:\\foo\\bar" "\\blah" append-path ] unit-test
[ t ] [ "" resource-path 2 tail exists? ] unit-test [ t ] [ "" resource-path 2 tail exists? ] unit-test
! win32-file-attributes
{
{ +read-only+ +hidden+ }
} [
3 win32-file-attributes
] unit-test

View File

@ -2,12 +2,11 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings USING: accessors alien alien.c-types alien.data alien.strings
alien.syntax arrays assocs classes.struct combinators alien.syntax arrays assocs classes.struct combinators
combinators.short-circuit continuations destructors environment combinators.short-circuit continuations destructors environment io
fry io io.backend io.binary io.buffers io.encodings.utf16n io.files io.backend io.binary io.buffers io.files io.files.private
io.files.private io.files.types io.pathnames io.ports io.files.types io.pathnames io.ports io.streams.c io.streams.null
io.streams.c io.streams.null io.timeouts kernel libc literals io.timeouts kernel libc literals locals math math.bitwise namespaces
locals make math math.bitwise namespaces sequences sequences specialized-arrays system threads tr windows windows.errors
specialized-arrays system threads tr windows windows.errors
windows.handles windows.kernel32 windows.shell32 windows.time windows.handles windows.kernel32 windows.shell32 windows.time
windows.types windows.winsock ; windows.types windows.winsock ;
SPECIALIZED-ARRAY: ushort SPECIALIZED-ARRAY: ushort
@ -291,28 +290,24 @@ SLOT: attributes
: set-file-normal-attribute ( path -- ) : set-file-normal-attribute ( path -- )
FILE_ATTRIBUTE_NORMAL set-file-attributes ; FILE_ATTRIBUTE_NORMAL set-file-attributes ;
: win32-file-attribute ( n symbol attr -- )
rot mask? [ , ] [ drop ] if ;
: win32-file-attributes ( n -- seq ) : win32-file-attributes ( n -- seq )
[ {
{ { +read-only+ FILE_ATTRIBUTE_READONLY }
[ +read-only+ FILE_ATTRIBUTE_READONLY win32-file-attribute ] { +hidden+ FILE_ATTRIBUTE_HIDDEN }
[ +hidden+ FILE_ATTRIBUTE_HIDDEN win32-file-attribute ] { +system+ FILE_ATTRIBUTE_SYSTEM }
[ +system+ FILE_ATTRIBUTE_SYSTEM win32-file-attribute ] { +directory+ FILE_ATTRIBUTE_DIRECTORY }
[ +directory+ FILE_ATTRIBUTE_DIRECTORY win32-file-attribute ] { +archive+ FILE_ATTRIBUTE_ARCHIVE }
[ +archive+ FILE_ATTRIBUTE_ARCHIVE win32-file-attribute ] { +device+ FILE_ATTRIBUTE_DEVICE }
[ +device+ FILE_ATTRIBUTE_DEVICE win32-file-attribute ] { +normal+ FILE_ATTRIBUTE_NORMAL }
[ +normal+ FILE_ATTRIBUTE_NORMAL win32-file-attribute ] { +temporary+ FILE_ATTRIBUTE_TEMPORARY }
[ +temporary+ FILE_ATTRIBUTE_TEMPORARY win32-file-attribute ] { +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE }
[ +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE win32-file-attribute ] { +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT }
[ +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT win32-file-attribute ] { +compressed+ FILE_ATTRIBUTE_COMPRESSED }
[ +compressed+ FILE_ATTRIBUTE_COMPRESSED win32-file-attribute ] { +offline+ FILE_ATTRIBUTE_OFFLINE }
[ +offline+ FILE_ATTRIBUTE_OFFLINE win32-file-attribute ] { +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED }
[ +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED win32-file-attribute ] { +encrypted+ FILE_ATTRIBUTE_ENCRYPTED }
[ +encrypted+ FILE_ATTRIBUTE_ENCRYPTED win32-file-attribute ] }
} cleave [ execute( -- y ) mask? [ drop f ] unless ] with { } assoc>map sift ;
] { } make ;
: win32-file-type ( n -- symbol ) : win32-file-type ( n -- symbol )
FILE_ATTRIBUTE_DIRECTORY mask? +directory+ +regular-file+ ? ; FILE_ATTRIBUTE_DIRECTORY mask? +directory+ +regular-file+ ? ;