@@ -351,28 +351,44 @@ final class LoggerTests: XCTestCase {
351
351
try ! FileManager . default. createDirectory ( at: existingWithComplete,
352
352
withIntermediateDirectories: true )
353
353
354
- // Make sure protections are correct
355
- XCTAssertEqual ( . complete, try ! protection ( at: root. path) )
356
- XCTAssertEqual ( . complete, try ! protection ( at: existingWithComplete. path) )
357
- XCTAssertNil ( try ! protection ( at: existingWithNone. path) )
354
+ // Create a buffer directory inside the root path (should inherit complete protection)
355
+ let buffers = root. appendingPathComponent ( " buffers " )
356
+ try ! FileManager . default. createDirectory ( at: buffers,
357
+ withIntermediateDirectories: true )
358
+
359
+ // Create a file under buffers to pretend like it's the ring buffer
360
+ let bufferFile = buffers. appendingPathComponent ( " bufferFile " )
361
+ FileManager . default. createFile ( atPath: bufferFile. path,
362
+ contents: " foobar " . data ( using: . ascii) )
363
+ try ! ( bufferFile as NSURL ) . setResourceValue ( URLFileProtection . complete, forKey: . fileProtectionKey)
358
364
359
365
// Test to see if disable protection works on a new path
366
+ XCTAssertEqual ( . complete, try ! protection ( at: root. path) )
360
367
let newPath = root. appendingPathComponent ( " newPath " )
361
368
XCTAssertFalse ( FileManager . default. fileExists ( atPath: newPath. path) )
362
369
try ! makeDirectoryAndDisableProtection ( at: newPath. path)
363
370
XCTAssertEqual ( . completeUntilFirstUserAuthentication,
364
371
try ! protection ( at: newPath. path) )
365
372
366
373
// Test to see if disable protection works on an existing path with complete
374
+ XCTAssertEqual ( . complete, try ! protection ( at: existingWithComplete. path) )
367
375
XCTAssertTrue ( FileManager . default. fileExists ( atPath: existingWithComplete. path) )
368
376
try ! makeDirectoryAndDisableProtection ( at: existingWithComplete. path)
369
377
XCTAssertEqual ( . completeUntilFirstUserAuthentication,
370
378
try ! protection ( at: existingWithComplete. path) )
371
379
372
380
// Test to see if disable protection works on an existing path with none
381
+ XCTAssertNil ( try ! protection ( at: existingWithNone. path) )
373
382
XCTAssertTrue ( FileManager . default. fileExists ( atPath: existingWithNone. path) )
374
383
try ! makeDirectoryAndDisableProtection ( at: existingWithNone. path)
375
384
XCTAssertNil ( try ! protection ( at: existingWithNone. path) )
385
+
386
+ // Test to see if disable protection works on all files under buffers
387
+ XCTAssertEqual ( . complete, try ! protection ( at: bufferFile. path) )
388
+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: bufferFile. path) )
389
+ try ! makeDirectoryAndDisableProtection ( at: root. path)
390
+ XCTAssertEqual ( . completeUntilFirstUserAuthentication,
391
+ try ! protection ( at: bufferFile. path) )
376
392
}
377
393
}
378
394
0 commit comments