7
7
See http://swift.org/LICENSE.txt for license information
8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
-------------------------------------------------------------------------
10
-
10
+
11
11
This file contains temporary shim functions for use during the adoption of
12
12
AbsolutePath and RelativePath. The eventual plan is to use the FileSystem
13
13
API for all of this, at which time this file will go way. But since it is
14
14
important to have a quality FileSystem API, we will evolve it slowly.
15
-
15
+
16
16
Meanwhile this file bridges the gap to let call sites be as clean as possible,
17
17
while making it fairly easy to find those calls later.
18
18
*/
@@ -24,17 +24,21 @@ import Foundation
24
24
public func resolveSymlinks( _ path: AbsolutePath ) throws -> AbsolutePath {
25
25
#if os(Windows)
26
26
let handle : HANDLE = path. pathString. withCString ( encodedAs: UTF16 . self) {
27
- CreateFileW ( $0, GENERIC_READ, DWORD ( FILE_SHARE_READ) , nil ,
28
- DWORD ( OPEN_EXISTING) , DWORD ( FILE_FLAG_BACKUP_SEMANTICS) , nil )
27
+ CreateFileW ( $0, GENERIC_READ, DWORD ( FILE_SHARE_READ) , nil ,
28
+ DWORD ( OPEN_EXISTING) , DWORD ( FILE_FLAG_BACKUP_SEMANTICS) , nil )
29
29
}
30
30
if handle == INVALID_HANDLE_VALUE { return path }
31
31
defer { CloseHandle ( handle) }
32
- return try withUnsafeTemporaryAllocation ( of: WCHAR . self, capacity: 261 ) {
33
- let dwLength : DWORD =
34
- GetFinalPathNameByHandleW ( handle, $0. baseAddress!, DWORD ( $0. count) ,
35
- DWORD ( FILE_NAME_NORMALIZED) )
36
- let path = String ( decodingCString: $0. baseAddress!, as: UTF16 . self)
37
- return try AbsolutePath ( path)
32
+
33
+ let dwLength : DWORD =
34
+ GetFinalPathNameByHandleW ( handle, nil , 0 , DWORD ( FILE_NAME_NORMALIZED) )
35
+ return try withUnsafeTemporaryAllocation ( of: WCHAR . self, capacity: Int ( dwLength) ) {
36
+ guard GetFinalPathNameByHandleW ( handle, $0. baseAddress!, DWORD ( $0. count) ,
37
+ DWORD ( FILE_NAME_NORMALIZED) ) == dwLength - 1 else {
38
+ throw FileSystemError ( . unknownOSError, path)
39
+ }
40
+ let path = String ( decodingCString: $0. baseAddress!, as: UTF16 . self)
41
+ return try AbsolutePath ( path)
38
42
}
39
43
#else
40
44
let pathStr = path. pathString
@@ -76,12 +80,12 @@ public func createSymlink(_ path: AbsolutePath, pointingAt dest: AbsolutePath, r
76
80
- Returns: a generator that walks the specified directory producing all
77
81
files therein. If recursively is true will enter any directories
78
82
encountered recursively.
79
-
83
+
80
84
- Warning: directories that cannot be entered due to permission problems
81
85
are silently ignored. So keep that in mind.
82
-
86
+
83
87
- Warning: Symbolic links that point to directories are *not* followed.
84
-
88
+
85
89
- Note: setting recursively to `false` still causes the generator to feed
86
90
you the directory; just not its contents.
87
91
*/
@@ -100,12 +104,12 @@ public func walk(
100
104
- Returns: a generator that walks the specified directory producing all
101
105
files therein. Directories are recursed based on the return value of
102
106
`recursing`.
103
-
107
+
104
108
- Warning: directories that cannot be entered due to permissions problems
105
109
are silently ignored. So keep that in mind.
106
-
110
+
107
111
- Warning: Symbolic links that point to directories are *not* followed.
108
-
112
+
109
113
- Note: returning `false` from `recursing` still produces that directory
110
114
from the generator; just not its contents.
111
115
*/
0 commit comments