1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: alien.c-types alien.strings alien.syntax classes.struct
5 core-foundation io.backend io.encodings.utf8 io.files.trash
8 IN: io.files.trash.macosx
13 { hidden UInt8[80] } ;
15 TYPEDEF: SInt32 OSStatus
17 TYPEDEF: UInt32 OptionBits
21 CONSTANT: kFSFileOperationDefaultOptions 0x00
22 CONSTANT: kFSFileOperationOverwrite 0x01
23 CONSTANT: kFSFileOperationSkipSourcePermissionErrors 0x02
24 CONSTANT: kFSFileOperationDoNotMoveAcrossVolumes 0x04
25 CONSTANT: kFSFileOperationSkipPreflight 0x08
27 CONSTANT: kFSPathMakeRefDefaultOptions 0x00
28 CONSTANT: kFSPathMakeRefDoNotFollowLeafSymlink 0x01
30 FUNCTION: OSStatus FSMoveObjectToTrashSync (
36 FUNCTION: char* GetMacOSStatusCommentString (
40 FUNCTION: OSStatus FSPathMakeRefWithOptions (
47 : check-err ( err -- )
48 dup noErr = [ drop ] [
49 GetMacOSStatusCommentString utf8 alien>string throw
52 ! FIXME: check isDirectory?
54 : <fs-ref> ( path -- fs-ref )
56 kFSPathMakeRefDoNotFollowLeafSymlink
58 [ f FSPathMakeRefWithOptions check-err ] keep ;
62 M: macosx send-to-trash ( path -- )
64 <fs-ref> f kFSFileOperationDefaultOptions
65 FSMoveObjectToTrashSync check-err ;