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.encodings.utf8 io.files.trash kernel system ;
7 IN: io.files.trash.macosx
12 { hidden UInt8[80] } ;
14 TYPEDEF: SInt32 OSStatus
16 TYPEDEF: UInt32 OptionBits
20 CONSTANT: kFSFileOperationDefaultOptions 0x00
21 CONSTANT: kFSFileOperationOverwrite 0x01
22 CONSTANT: kFSFileOperationSkipSourcePermissionErrors 0x02
23 CONSTANT: kFSFileOperationDoNotMoveAcrossVolumes 0x04
24 CONSTANT: kFSFileOperationSkipPreflight 0x08
26 CONSTANT: kFSPathMakeRefDefaultOptions 0x00
27 CONSTANT: kFSPathMakeRefDoNotFollowLeafSymlink 0x01
29 FUNCTION: OSStatus FSMoveObjectToTrashSync (
35 FUNCTION: char* GetMacOSStatusCommentString (
39 FUNCTION: OSStatus FSPathMakeRefWithOptions (
46 : check-err ( err -- )
47 dup noErr = [ drop ] [
48 GetMacOSStatusCommentString utf8 alien>string throw
51 ! FIXME: check isDirectory?
53 : <fs-ref> ( path -- fs-ref )
55 kFSPathMakeRefDoNotFollowLeafSymlink
57 [ f FSPathMakeRefWithOptions check-err ] keep ;
61 M: macosx send-to-trash ( path -- )
62 <fs-ref> f kFSFileOperationDefaultOptions
63 FSMoveObjectToTrashSync check-err ;