Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the type of intPermission to UInt16 #41

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## [x.y.z](https://github.com/sushichop/Puppy/releases/tag/x.y.z) (yyyy-mm-dd)

- Remove concurrency features. [#39](https://github.com/sushichop/Puppy/pull/39)
- Fix the default rotation type to `numbering`. [#40](https://github.com/sushichop/Puppy/pull/40)
- Fix the default rotation type to `numbering`. [#40](https://github.com/sushichop/Puppy/pull/40)
- Change the type of intPermission to `UInt16`. [#41](https://github.com/sushichop/Puppy/pull/41)

## [0.4.0](https://github.com/sushichop/Puppy/releases/tag/0.4.0) (2022-01-31)

Expand Down
12 changes: 6 additions & 6 deletions Sources/Puppy/FileLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class FileLogger: BaseLogger {
public private(set) var flushMode: FlushMode

var filePermission: Permission
var intPermission: Int16 {
return Int16(filePermission, radix: 8)!
var uintPermission: UInt16 {
return UInt16(filePermission, radix: 8)!
}

var fileHandle: FileHandle!
Expand Down Expand Up @@ -91,7 +91,7 @@ public class FileLogger: BaseLogger {
}

if !FileManager.default.fileExists(atPath: fileURL.path) {
let successful = FileManager.default.createFile(atPath: fileURL.path, contents: nil, attributes: [FileAttributeKey.posixPermissions: intPermission])
let successful = FileManager.default.createFile(atPath: fileURL.path, contents: nil, attributes: [FileAttributeKey.posixPermissions: uintPermission])
if successful {
debug("succeeded in creating filePath")
} else {
Expand Down Expand Up @@ -119,9 +119,9 @@ public class FileLogger: BaseLogger {
}

private func validateFilePermssion(_ filePermission: Permission) throws {
let min = Int16("000", radix: 8)!
let max = Int16("777", radix: 8)!
if let intPermission = Int16(filePermission, radix: 8), intPermission >= min, intPermission <= max {
let min = UInt16("000", radix: 8)!
let max = UInt16("777", radix: 8)!
if let uintPermission = Int16(filePermission, radix: 8), uintPermission >= min, uintPermission <= max {
} else {
throw FileError.invalidPermssion(filePermission)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/PuppyTests/FileLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ final class FileLoggerTests: XCTestCase {

let attribute = try FileManager.default.attributesOfItem(atPath: fileURL.path)
// swiftlint:disable force_cast
let permission = attribute[FileAttributeKey.posixPermissions] as! Int16
let permission = attribute[FileAttributeKey.posixPermissions] as! UInt16
// swiftlint:enable force_cast
let expectedPermission = Int16("600", radix: 8)!
let expectedPermission = UInt16("600", radix: 8)!
XCTAssertEqual(permission, expectedPermission)

_ = fileLogger.delete(fileURL)
Expand Down