Skip to content

Commit 27ba77b

Browse files
committed
UPdated for 07-25 chain
1 parent c8d4732 commit 27ba77b

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

Sources/PerfectLib/Dir.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct Dir {
6969
public func create(perms: PermissionMode = [.rwxUser, .rxGroup, .rxOther]) throws {
7070
let pth = realPath
7171
var currPath = pth.begins(with: "/") ? "/" : ""
72-
for component in pth.pathComponents where component != "/" {
72+
for component in URL(fileURLWithPath: pth).pathComponents where component != "/" {
7373
currPath += component
7474
defer {
7575
currPath += "/"
@@ -95,15 +95,15 @@ public struct Dir {
9595

9696
/// Returns the name of the directory.
9797
public var name: String {
98-
return internalPath.lastPathComponent
98+
return URL(fileURLWithPath: internalPath).lastPathComponent
9999
}
100100

101101
/// Returns a Dir object representing the current Dir's parent. Returns nil if there is no parent.
102102
public var parentDir: Dir? {
103103
guard internalPath != "/" else {
104104
return nil // can not go up
105105
}
106-
return Dir(internalPath.stringByDeletingLastPathComponent)
106+
return Dir(URL(fileURLWithPath: internalPath).deletingLastPathComponent().path)
107107
}
108108

109109
/// Returns the path to the current directory.
@@ -122,7 +122,7 @@ public struct Dir {
122122
}
123123

124124
var realPath: String {
125-
return internalPath.stringByResolvingSymlinksInPath
125+
return URL(fileURLWithPath: internalPath).resolvingSymlinksInPath().path
126126
}
127127

128128
#if os(Linux)

Sources/PerfectLib/DynamicLoader.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#else
2323
import Darwin
2424
#endif
25+
import Foundation
2526

2627
struct DynamicLoader {
2728

@@ -37,9 +38,9 @@ struct DynamicLoader {
3738
}
3839

3940
func loadFramework(atPath at: String) -> Bool {
40-
let resolvedPath = at.stringByResolvingSymlinksInPath
41-
let moduleName = resolvedPath.lastPathComponent.stringByDeletingPathExtension
42-
let file = File(resolvedPath + "/" + moduleName)
41+
let resolvedPath = URL(fileURLWithPath: at).resolvingSymlinksInPath()
42+
let moduleName = resolvedPath.deletingPathExtension().lastPathComponent
43+
let file = File(resolvedPath.path + "/" + moduleName)
4344
guard file.exists else {
4445
return false
4546
}
@@ -48,11 +49,10 @@ struct DynamicLoader {
4849
}
4950

5051
func loadLibrary(atPath at: String) -> Bool {
51-
var fileName = at.lastPathComponent
52-
if fileName.begins(with: "lib") {
53-
fileName.characters.removeFirst(3)
52+
var moduleName = URL(fileURLWithPath: at).deletingPathExtension().lastPathComponent
53+
if moduleName.begins(with: "lib") {
54+
moduleName.characters.removeFirst(3)
5455
}
55-
let moduleName = fileName.stringByDeletingPathExtension
5656
return self.loadRealPath(at, moduleName: moduleName)
5757
}
5858

Sources/PerfectLib/File.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ let F_OK: Int32 = 0
4545
import Darwin
4646
#endif
4747

48+
import Foundation
49+
4850
let fileCopyBufferSize = 16384
4951

5052
/// Provides access to a file on the local file system
@@ -85,7 +87,7 @@ public class File {
8587
guard lastChar != "/" && lastChar != "." else {
8688
return trailPath
8789
}
88-
return internalPath.stringByDeletingLastPathComponent + "/" + trailPath
90+
return URL(fileURLWithPath: internalPath).deletingLastPathComponent().path + "/" + trailPath
8991
}
9092

9193
/// Returns the modification date for the file in the standard UNIX format of seconds since 1970/01/01 00:00:00 GMT

Sources/PerfectLib/Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ extension String {
435435
return nil != self.range(ofString: strng)
436436
}
437437
}
438-
438+
/*
439439
#if os(OSX)
440440
extension String {
441441

@@ -583,7 +583,7 @@ extension String {
583583
}
584584
}
585585
#endif
586-
586+
*/
587587
extension String {
588588
func begins(with str: String) -> Bool {
589589
return self.characters.starts(with: str.characters)

Tests/PerfectLib/PerfectLibTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,13 @@ class PerfectLibTests: XCTestCase {
466466

467467
func testDeletingPathExtension() {
468468
let path = "/a/b/c.txt"
469-
let del = path.stringByDeletingPathExtension
469+
let del = URL(fileURLWithPath: path).deletingPathExtension().path
470470
XCTAssert("/a/b/c" == del)
471471
}
472472

473473
func testGetPathExtension() {
474474
let path = "/a/b/c.txt"
475-
let ext = path.pathExtension
475+
let ext = URL(fileURLWithPath: path).pathExtension
476476
XCTAssert("txt" == ext)
477477
}
478478

@@ -487,7 +487,7 @@ class PerfectLibTests: XCTestCase {
487487

488488
while unPath != "/tmp" {
489489
try Dir(unPath).delete()
490-
unPath = unPath.stringByDeletingLastPathComponent
490+
unPath = URL(fileURLWithPath: unPath).deletingLastPathComponent().path
491491
}
492492
} catch {
493493
XCTAssert(false, "Error while creating dirs: \(error)")

0 commit comments

Comments
 (0)