io.files.windows: fix incorrect parsing of file attribute bitfield in win32-file-attributes
parent
e8841a4967
commit
e35087fb22
|
@ -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
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2010 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: io.files io.pathnames kernel tools.test io.backend
|
||||
io.files.windows splitting sequences io.pathnames.private ;
|
||||
USING: io.backend io.files io.files.windows io.pathnames kernel
|
||||
sequences splitting tools.test ;
|
||||
IN: io.files.windows.tests
|
||||
|
||||
[ 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
|
||||
[ t ] [ "" resource-path 2 tail exists? ] unit-test
|
||||
|
||||
! win32-file-attributes
|
||||
{
|
||||
{ +read-only+ +hidden+ }
|
||||
} [
|
||||
3 win32-file-attributes
|
||||
] unit-test
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien alien.c-types alien.data alien.strings
|
||||
alien.syntax arrays assocs classes.struct combinators
|
||||
combinators.short-circuit continuations destructors environment
|
||||
fry io io.backend io.binary io.buffers io.encodings.utf16n io.files
|
||||
io.files.private io.files.types io.pathnames io.ports
|
||||
io.streams.c io.streams.null io.timeouts kernel libc literals
|
||||
locals make math math.bitwise namespaces sequences
|
||||
specialized-arrays system threads tr windows windows.errors
|
||||
combinators.short-circuit continuations destructors environment io
|
||||
io.backend io.binary io.buffers io.files io.files.private
|
||||
io.files.types io.pathnames io.ports io.streams.c io.streams.null
|
||||
io.timeouts kernel libc literals locals math math.bitwise namespaces
|
||||
sequences specialized-arrays system threads tr windows windows.errors
|
||||
windows.handles windows.kernel32 windows.shell32 windows.time
|
||||
windows.types windows.winsock ;
|
||||
SPECIALIZED-ARRAY: ushort
|
||||
|
@ -291,28 +290,24 @@ SLOT: attributes
|
|||
: set-file-normal-attribute ( path -- )
|
||||
FILE_ATTRIBUTE_NORMAL set-file-attributes ;
|
||||
|
||||
: win32-file-attribute ( n symbol attr -- )
|
||||
rot mask? [ , ] [ drop ] if ;
|
||||
|
||||
: win32-file-attributes ( n -- seq )
|
||||
[
|
||||
{
|
||||
[ +read-only+ FILE_ATTRIBUTE_READONLY win32-file-attribute ]
|
||||
[ +hidden+ FILE_ATTRIBUTE_HIDDEN win32-file-attribute ]
|
||||
[ +system+ FILE_ATTRIBUTE_SYSTEM win32-file-attribute ]
|
||||
[ +directory+ FILE_ATTRIBUTE_DIRECTORY win32-file-attribute ]
|
||||
[ +archive+ FILE_ATTRIBUTE_ARCHIVE win32-file-attribute ]
|
||||
[ +device+ FILE_ATTRIBUTE_DEVICE win32-file-attribute ]
|
||||
[ +normal+ FILE_ATTRIBUTE_NORMAL win32-file-attribute ]
|
||||
[ +temporary+ FILE_ATTRIBUTE_TEMPORARY win32-file-attribute ]
|
||||
[ +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE win32-file-attribute ]
|
||||
[ +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT win32-file-attribute ]
|
||||
[ +compressed+ FILE_ATTRIBUTE_COMPRESSED win32-file-attribute ]
|
||||
[ +offline+ FILE_ATTRIBUTE_OFFLINE win32-file-attribute ]
|
||||
[ +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED win32-file-attribute ]
|
||||
[ +encrypted+ FILE_ATTRIBUTE_ENCRYPTED win32-file-attribute ]
|
||||
} cleave
|
||||
] { } make ;
|
||||
{
|
||||
{ +read-only+ FILE_ATTRIBUTE_READONLY }
|
||||
{ +hidden+ FILE_ATTRIBUTE_HIDDEN }
|
||||
{ +system+ FILE_ATTRIBUTE_SYSTEM }
|
||||
{ +directory+ FILE_ATTRIBUTE_DIRECTORY }
|
||||
{ +archive+ FILE_ATTRIBUTE_ARCHIVE }
|
||||
{ +device+ FILE_ATTRIBUTE_DEVICE }
|
||||
{ +normal+ FILE_ATTRIBUTE_NORMAL }
|
||||
{ +temporary+ FILE_ATTRIBUTE_TEMPORARY }
|
||||
{ +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE }
|
||||
{ +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT }
|
||||
{ +compressed+ FILE_ATTRIBUTE_COMPRESSED }
|
||||
{ +offline+ FILE_ATTRIBUTE_OFFLINE }
|
||||
{ +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED }
|
||||
{ +encrypted+ FILE_ATTRIBUTE_ENCRYPTED }
|
||||
}
|
||||
[ execute( -- y ) mask? [ drop f ] unless ] with { } assoc>map sift ;
|
||||
|
||||
: win32-file-type ( n -- symbol )
|
||||
FILE_ATTRIBUTE_DIRECTORY mask? +directory+ +regular-file+ ? ;
|
||||
|
|
Loading…
Reference in New Issue