ds-store/alias: fix for Mac OS X 10.4

This commit is contained in:
Matthew Flatt 2013-09-10 07:47:31 -06:00
parent 24fc16674b
commit 1829a03bb6

View File

@ -14,7 +14,29 @@
(get-ffi-obj 'FSNewAliasFromPath (get-ffi-obj 'FSNewAliasFromPath
CoreServices CoreServices
(_fun _path _path _int (h : (_ptr o _pointer)) (_ptr io _int) -> (r : _int) -> (if (zero? r) h #f)) (_fun _path _path _int (h : (_ptr o _pointer)) (_ptr io _int) -> (r : _int) -> (if (zero? r) h #f))
(lambda () #f)))
;; Fallback when FSNewAliasFromPath is not available:
(define _FSRef _pointer) ; 80 bytes
(define FSPathMakeRef
(get-ffi-obj 'FSPathMakeRef
CoreServices
(_fun _path _FSRef (_pointer = #f) -> (r : _int)
-> (unless (zero? r)
(error 'FSPathMakeRef "failed")))))
(define FSNewAliasUnicode
(get-ffi-obj 'FSNewAliasUnicode
CoreServices
(_fun _FSRef
_FSRef
_uint
_string/utf-16
(h : (_ptr o _pointer))
(_ptr io _int)
-> (r : _int)
-> (if (zero? r) h #f))
make-unavailable)) make-unavailable))
(define GetAliasSize (define GetAliasSize
(get-ffi-obj 'GetAliasSize (get-ffi-obj 'GetAliasSize
CoreServices CoreServices
@ -29,10 +51,21 @@
(define (path->alias-bytes file (define (path->alias-bytes file
#:wrt [wrt #f]) #:wrt [wrt #f])
(define h (define h
(FSNewAliasFromPath wrt (if FSNewAliasFromPath
file (FSNewAliasFromPath wrt
0 file
0)) 0
0)
(let ([wrt-fs (and wrt (malloc 80))]
[fs (malloc 80)])
(when wrt (FSPathMakeRef wrt wrt-fs))
(define-values (base name dir?) (split-path file))
(FSPathMakeRef base fs)
(FSNewAliasUnicode wrt-fs
fs
(string-length (path->string name)) ; FIXME: should be utf-16 count
(path->string name)
0))))
(and h (and h
(let ([sz (GetAliasSize h)]) (let ([sz (GetAliasSize h)])
(define bstr (make-bytes sz)) (define bstr (make-bytes sz))