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 @@ -231,7 +231,24 @@ open class FileManager : NSObject {
231
231
return urls
232
232
}
233
233
#endif
234
-
234
+
235
+ private lazy var xdgHomeDirectory : String = {
236
+ let key = " HOME= "
237
+ if let contents = try ? String ( contentsOfFile: " /etc/default/useradd " , encoding: . utf8) {
238
+ for line in contents. components ( separatedBy: " \n " ) {
239
+ if line. hasPrefix ( key) {
240
+ let index = line. index ( line. startIndex, offsetBy: key. count)
241
+ let str = String ( line [ index... ] ) as NSString
242
+ let homeDir = str. trimmingCharacters ( in: CharacterSet . whitespaces)
243
+ if homeDir. count > 0 {
244
+ return homeDir
245
+ }
246
+ }
247
+ }
248
+ }
249
+ return " /home "
250
+ } ( )
251
+
235
252
private func xdgURLs( for directory: SearchPathDirectory , in domain: _SearchPathDomain ) -> [ URL ] {
236
253
// FHS/XDG-compliant OSes:
237
254
switch directory {
@@ -263,7 +280,7 @@ open class FileManager : NSObject {
263
280
264
281
case . userDirectory:
265
282
guard domain == . local else { return [ ] }
266
- return [ URL ( fileURLWithPath: " /home " , isDirectory: true ) ]
283
+ return [ URL ( fileURLWithPath: xdgHomeDirectory , isDirectory: true ) ]
267
284
268
285
case . moviesDirectory:
269
286
return [ _XDGUserDirectory. videos. url ]
You can’t perform that action at this time.
0 commit comments