-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability for a persistence to auto-prune snapshot iterations…
… and assets according to the specified retention policy
- Loading branch information
1 parent
f1a6a91
commit 2c259ec
Showing
10 changed files
with
786 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Sources/CodableDatastore/Persistence/Disk Persistence/FileManager+Helpers.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// FileManager+Helpers.swift | ||
// CodableDatastore | ||
// | ||
// Created by Dimitri Bouniol on 2024-09-08. | ||
// Copyright © 2023-24 Mochi Development, Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum DirectoryRemovalError: Error { | ||
case missingEnumerator | ||
} | ||
|
||
extension FileManager { | ||
func removeDirectoryIfEmpty(url: URL, recursivelyRemoveParents: Bool) throws { | ||
guard let enumerator = self.enumerator(at: url, includingPropertiesForKeys: [], options: [.skipsHiddenFiles, .skipsSubdirectoryDescendants, .skipsPackageDescendants, .includesDirectoriesPostOrder]) | ||
else { throw DirectoryRemovalError.missingEnumerator } | ||
|
||
for case _ as URL in enumerator { | ||
/// If this is called a single time, then we don't have an empty directory, and can stop | ||
return | ||
} | ||
|
||
try self.removeItem(at: url) | ||
|
||
guard recursivelyRemoveParents else { return } | ||
try self.removeDirectoryIfEmpty(url: url.deletingLastPathComponent(), recursivelyRemoveParents: recursivelyRemoveParents) | ||
} | ||
} |
Oops, something went wrong.