Swift 5 --warnings

This commit is contained in:
Max Howell
2019-01-24 15:02:03 -05:00
parent 2388c384a1
commit fdff3bcc05
3 changed files with 14 additions and 14 deletions

View File

@@ -10,17 +10,17 @@ public extension Bundle {
} }
/// Returns the path for the shared-frameworks directory in this bundle. /// Returns the path for the shared-frameworks directory in this bundle.
public var sharedFrameworks: Path? { var sharedFrameworks: Path? {
return sharedFrameworksPath.flatMap(Path.init) return sharedFrameworksPath.flatMap(Path.init)
} }
/// Returns the path for the resources directory in this bundle. /// Returns the path for the resources directory in this bundle.
public var resources: Path? { var resources: Path? {
return resourcePath.flatMap(Path.init) return resourcePath.flatMap(Path.init)
} }
/// Returns the path for this bundle. /// Returns the path for this bundle.
public var path: Path { var path: Path {
return Path(string: bundlePath) return Path(string: bundlePath)
} }
} }

View File

@@ -4,7 +4,7 @@ public extension Path {
/// - Note: If file is already locked, does nothing /// - Note: If file is already locked, does nothing
/// - Note: If file doesnt exist, throws /// - Note: If file doesnt exist, throws
@discardableResult @discardableResult
public func lock() throws -> Path { func lock() throws -> Path {
var attrs = try FileManager.default.attributesOfItem(atPath: string) var attrs = try FileManager.default.attributesOfItem(atPath: string)
let b = attrs[.immutable] as? Bool ?? false let b = attrs[.immutable] as? Bool ?? false
if !b { if !b {
@@ -17,7 +17,7 @@ public extension Path {
/// - Note: If file isnt locked, does nothing /// - Note: If file isnt locked, does nothing
/// - Note: If file doesnt exist, does nothing /// - Note: If file doesnt exist, does nothing
@discardableResult @discardableResult
public func unlock() throws -> Path { func unlock() throws -> Path {
var attrs: [FileAttributeKey: Any] var attrs: [FileAttributeKey: Any]
do { do {
attrs = try FileManager.default.attributesOfItem(atPath: string) attrs = try FileManager.default.attributesOfItem(atPath: string)
@@ -38,7 +38,7 @@ public extension Path {
Path.home.join("foo").chmod(0o555) Path.home.join("foo").chmod(0o555)
*/ */
@discardableResult @discardableResult
public func chmod(_ octal: Int) throws -> Path { func chmod(_ octal: Int) throws -> Path {
try FileManager.default.setAttributes([.posixPermissions: octal], ofItemAtPath: string) try FileManager.default.setAttributes([.posixPermissions: octal], ofItemAtPath: string)
return self return self
} }
@@ -48,7 +48,7 @@ public extension Path {
- Note: Returns the creation time if there is no modification time. - Note: Returns the creation time if there is no modification time.
- Note: Returns UNIX-time-zero if neither are available, though this *should* be impossible. - Note: Returns UNIX-time-zero if neither are available, though this *should* be impossible.
*/ */
public var mtime: Date { var mtime: Date {
do { do {
let attrs = try FileManager.default.attributesOfItem(atPath: string) let attrs = try FileManager.default.attributesOfItem(atPath: string)
return attrs[.modificationDate] as? Date ?? attrs[.creationDate] as? Date ?? Date(timeIntervalSince1970: 0) return attrs[.modificationDate] as? Date ?? attrs[.creationDate] as? Date ?? Date(timeIntervalSince1970: 0)

View File

@@ -11,7 +11,7 @@ public extension Path {
- SeeAlso: `copy(into:overwrite:)` - SeeAlso: `copy(into:overwrite:)`
*/ */
@discardableResult @discardableResult
public func copy(to: Path, overwrite: Bool = false) throws -> Path { func copy(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.isFile, isFile { if overwrite, to.isFile, isFile {
try FileManager.default.removeItem(at: to.url) try FileManager.default.removeItem(at: to.url)
} }
@@ -34,7 +34,7 @@ public extension Path {
- SeeAlso: `copy(into:overwrite:)` - SeeAlso: `copy(into:overwrite:)`
*/ */
@discardableResult @discardableResult
public func copy(into: Path, overwrite: Bool = false) throws -> Path { func copy(into: Path, overwrite: Bool = false) throws -> Path {
if !into.exists { if !into.exists {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true) try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
} }
@@ -64,7 +64,7 @@ public extension Path {
- SeeAlso: move(into:overwrite:) - SeeAlso: move(into:overwrite:)
*/ */
@discardableResult @discardableResult
public func move(to: Path, overwrite: Bool = false) throws -> Path { func move(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.exists { if overwrite, to.exists {
try FileManager.default.removeItem(at: to.url) try FileManager.default.removeItem(at: to.url)
} }
@@ -84,7 +84,7 @@ public extension Path {
- SeeAlso: move(into:overwrite:) - SeeAlso: move(into:overwrite:)
*/ */
@discardableResult @discardableResult
public func move(into: Path) throws -> Path { func move(into: Path) throws -> Path {
if !into.exists { if !into.exists {
try into.mkpath() try into.mkpath()
} else if !into.isDirectory { } else if !into.isDirectory {
@@ -97,7 +97,7 @@ public extension Path {
/// Deletes the path, recursively if a directory. /// Deletes the path, recursively if a directory.
@inlinable @inlinable
public func delete() throws { func delete() throws {
try FileManager.default.removeItem(at: url) try FileManager.default.removeItem(at: url)
} }
@@ -137,7 +137,7 @@ public extension Path {
- Returns: `self` to allow chaining. - Returns: `self` to allow chaining.
*/ */
@discardableResult @discardableResult
public func mkdir() throws -> Path { func mkdir() throws -> Path {
try _foo { try _foo {
try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil) try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil)
} }
@@ -150,7 +150,7 @@ public extension Path {
- Returns: `self` to allow chaining. - Returns: `self` to allow chaining.
*/ */
@discardableResult @discardableResult
public func mkpath() throws -> Path { func mkpath() throws -> Path {
try _foo { try _foo {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil) try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
} }