Commit 5de7f4b3 authored by Johannes Schriewer's avatar Johannes Schriewer

Merge pull request #6 from AnarchyTools/file-stress

Various file-related issues
parents 5556b96b c0cb6a85
Pipeline #1729 passed with stage
......@@ -27,7 +27,7 @@ public class File {
private(set) public var path: Path?
/// take ownership of the file descriptor/pointer
private let closeWhenDeallocated: Bool
private var closeWhenDeallocated: Bool
/// File mode
public enum Mode:String {
......@@ -85,12 +85,13 @@ public class File {
openMode += "b"
}
self.path = path
self.closeWhenDeallocated = true
self.closeWhenDeallocated = false
self.fp = fopen(path.description, openMode)
if self.fp == nil {
throw errnoToError(errno: errno)
}
self.closeWhenDeallocated = true
}
/// Initialize with a file descriptor
......
......@@ -157,7 +157,7 @@ public class Log {
private class func _fwrite(_ stream: UnsafeMutablePointer<FILE>, _ data: String) {
let buf = [CChar].fromString(data)
fwrite(buf, buf.count, 1, stream)
fwrite(buf, buf.count - 1, 1, stream)
}
/// Only use class functions please
......
......@@ -183,7 +183,11 @@ class FSTests: XCTestCase {
try FS.touchItem(path: p)
XCTAssert(FS.fileExists(path: p) == true)
let gid = try FS.getGroup(path: p)
let everyone = try FS.resolveGroup(name: "everyone")
#if os(Linux)
let everyone = try FS.resolveGroup(name: "nogroup")
#else
let everyone = try FS.resolveGroup(name: "everyone")
#endif
XCTAssertNotNil(everyone)
try FS.setGroup(path: p, newGroup: everyone!)
let newGroup = try FS.getGroup(path: p)
......@@ -197,6 +201,11 @@ class FSTests: XCTestCase {
}
}
func testLoadNonexistentFile() {
let p = Path("doesnotexist.file")
let _ = try? File(path: p, mode: .ReadOnly)
}
}
extension FSTests {
......@@ -214,7 +223,8 @@ extension FSTests {
("testChmodFile", testChmodFile),
("testResolveGroup", testResolveGroup),
("testResolveUser", testResolveUser),
("testSetGroup", testSetGroup)
("testSetGroup", testSetGroup),
("testLoadNonexistentFile", testLoadNonexistentFile)
]
}
}
\ No newline at end of file
......@@ -171,10 +171,11 @@ class PathTests: XCTestCase {
func testHomeDir() {
if let p = Path.homeDirectory() {
#if os(Linux)
XCTAssert(p.components.count == 2)
if p.components.count >= 2 {
XCTAssert(p.components[0] == "home")
}
XCTAssert(p.components.count > 0, "Home dir has \(p.components.count) components")
// disabled because CI has something other than /home/ci
// if p.components.count >= 2 {
// XCTAssert(p.components[0] == "home")
// }
XCTAssert(p.isAbsolute == true)
#else
XCTAssert(p.components.count == 2)
......
......@@ -25,4 +25,5 @@ XCTMain([
testCase(PathTests.allTests),
testCase(DateTests.allTests),
testCase(LoggerTests.allTests),
testCase(FSTests.allTests)
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment