]> gitweb.factorcode.org Git - factor.git/blob - extra/io/files/trash/macosx/macosx.factor
classes.struct: moving to new/boa instead of <struct>/<struct-boa>
[factor.git] / extra / io / files / trash / macosx / macosx.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: alien.c-types alien.strings alien.syntax classes.struct
5 core-foundation io.backend io.encodings.utf8 io.files.trash
6 kernel system ;
7
8 IN: io.files.trash.macosx
9
10 <PRIVATE
11
12 STRUCT: FSRef
13     { hidden UInt8[80] } ;
14
15 TYPEDEF: SInt32 OSStatus
16
17 TYPEDEF: UInt32 OptionBits
18
19 CONSTANT: noErr 0
20
21 CONSTANT: kFSFileOperationDefaultOptions 0x00
22 CONSTANT: kFSFileOperationOverwrite 0x01
23 CONSTANT: kFSFileOperationSkipSourcePermissionErrors 0x02
24 CONSTANT: kFSFileOperationDoNotMoveAcrossVolumes 0x04
25 CONSTANT: kFSFileOperationSkipPreflight 0x08
26
27 CONSTANT: kFSPathMakeRefDefaultOptions 0x00
28 CONSTANT: kFSPathMakeRefDoNotFollowLeafSymlink 0x01
29
30 FUNCTION: OSStatus FSMoveObjectToTrashSync (
31     FSRef* source,
32     FSRef* target,
33     OptionBits options
34 )
35
36 FUNCTION: char* GetMacOSStatusCommentString (
37     OSStatus err
38 )
39
40 FUNCTION: OSStatus FSPathMakeRefWithOptions (
41     UInt8* path,
42     OptionBits options,
43     FSRef* ref,
44     Boolean* isDirectory
45 )
46
47 : check-err ( err -- )
48     dup noErr = [ drop ] [
49         GetMacOSStatusCommentString utf8 alien>string throw
50     ] if ;
51
52 ! FIXME: check isDirectory?
53
54 : <fs-ref> ( path -- fs-ref )
55     utf8 string>alien
56     kFSPathMakeRefDoNotFollowLeafSymlink
57     FSRef new
58     [ f FSPathMakeRefWithOptions check-err ] keep ;
59
60 PRIVATE>
61
62 M: macosx send-to-trash ( path -- )
63     normalize-path
64     <fs-ref> f kFSFileOperationDefaultOptions
65     FSMoveObjectToTrashSync check-err ;