File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -223,7 +223,24 @@ open class FileManager : NSObject {
223
223
return urls
224
224
}
225
225
#endif
226
-
226
+
227
+ private lazy var xdgHomeDirectory : String = {
228
+ let key = " HOME= "
229
+ if let contents = try ? String ( contentsOfFile: " /etc/default/useradd " , encoding: . utf8) {
230
+ for line in contents. components ( separatedBy: " \n " ) {
231
+ if line. hasPrefix ( key) {
232
+ let index = line. index ( line. startIndex, offsetBy: key. count)
233
+ let str = String ( line [ index... ] ) as NSString
234
+ let homeDir = str. trimmingCharacters ( in: CharacterSet . whitespaces)
235
+ if homeDir. count > 0 {
236
+ return homeDir
237
+ }
238
+ }
239
+ }
240
+ }
241
+ return " /home "
242
+ } ( )
243
+
227
244
private func xdgURLs( for directory: SearchPathDirectory , in domain: _SearchPathDomain ) -> [ URL ] {
228
245
// FHS/XDG-compliant OSes:
229
246
switch directory {
@@ -255,7 +272,7 @@ open class FileManager : NSObject {
255
272
256
273
case . userDirectory:
257
274
guard domain == . local else { return [ ] }
258
- return [ URL ( fileURLWithPath: " /home " , isDirectory: true ) ]
275
+ return [ URL ( fileURLWithPath: xdgHomeDirectory , isDirectory: true ) ]
259
276
260
277
case . moviesDirectory:
261
278
return [ _XDGUserDirectory. videos. url ]
You can’t perform that action at this time.
0 commit comments