-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate executables to download/offload directories, reorganize …
…project structure
- Loading branch information
Showing
18 changed files
with
712 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
92 changes: 92 additions & 0 deletions
92
icloud-backup/icloud-backup.xcodeproj/xcshareddata/xcschemes/iclouddownload.xcscheme
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,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1250" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4317FCF26BA6CAB0012CCA6" | ||
BuildableName = "iclouddownload" | ||
BlueprintName = "iclouddownload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4317FCF26BA6CAB0012CCA6" | ||
BuildableName = "iclouddownload" | ||
BlueprintName = "iclouddownload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<CommandLineArguments> | ||
<CommandLineArgument | ||
argument = "--version" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "--verbose" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "--base "/Users/guenther/Documents/jobs"" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
</CommandLineArguments> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4317FCF26BA6CAB0012CCA6" | ||
BuildableName = "iclouddownload" | ||
BlueprintName = "iclouddownload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
92 changes: 92 additions & 0 deletions
92
icloud-backup/icloud-backup.xcodeproj/xcshareddata/xcschemes/icloudoffload.xcscheme
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,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1250" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4D287BE26BAE77A00EE9157" | ||
BuildableName = "icloudoffload" | ||
BlueprintName = "icloudoffload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4D287BE26BAE77A00EE9157" | ||
BuildableName = "icloudoffload" | ||
BlueprintName = "icloudoffload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<CommandLineArguments> | ||
<CommandLineArgument | ||
argument = "--base "/Users/guenther/Documents/music"" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "--verbose" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "--version" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
</CommandLineArguments> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4D287BE26BAE77A00EE9157" | ||
BuildableName = "icloudoffload" | ||
BlueprintName = "icloudoffload" | ||
ReferencedContainer = "container:icloud-backup.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
File renamed without changes.
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
File renamed without changes.
6 changes: 1 addition & 5 deletions
6
...ud-backup/icloud-backup/analyze_dst.swift → icloud-backup/icloudbackup/walk_dst.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
File renamed without changes.
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,41 @@ | ||
import Foundation | ||
|
||
enum ArgumentError: Error { | ||
case BaseUnset | ||
case BaseDoesNotExist | ||
} | ||
|
||
struct CLI { | ||
private let options: IclouddownloadOptions | ||
private let version: String | ||
|
||
init(options: IclouddownloadOptions, version: String) { | ||
self.options = options | ||
self.version = version | ||
} | ||
|
||
func run() throws { | ||
if options.version == true { | ||
print("Version " + self.version) | ||
return | ||
} | ||
|
||
var baseUrl: URL? | ||
let fileManager = FileManager.default | ||
var isDir : ObjCBool = true | ||
|
||
if options.base == "" { | ||
throw ArgumentError.BaseUnset | ||
} else { | ||
if fileManager.fileExists(atPath: options.base, isDirectory: &isDir) { | ||
baseUrl = URL(fileURLWithPath: options.base) | ||
} else { | ||
throw ArgumentError.BaseDoesNotExist | ||
} | ||
} | ||
|
||
if let safeBaseUrl = baseUrl { | ||
DownloadItems(baseURL: safeBaseUrl, verbose: options.verbose) | ||
} | ||
} | ||
} |
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,24 @@ | ||
import Foundation | ||
import ArgumentParser | ||
|
||
struct IclouddownloadOptions: ParsableArguments { | ||
@Flag(name: .long, help: "Print version and exit.") var version = false | ||
@Flag(name: .long, help: "Show the paths of all downloaded files.") var verbose = false | ||
@Option(help: ArgumentHelp("Set the base path.", valueName: "path")) var base = "" | ||
// --help is automatically included | ||
} | ||
|
||
let cli = CLI(options: IclouddownloadOptions.parseOrExit(), version: "1.4.0") | ||
|
||
do { | ||
try cli.run() | ||
} catch ArgumentError.BaseUnset { | ||
fputs("Base path must be set (--base <path>)", stderr) | ||
exit(1) | ||
} catch ArgumentError.BaseDoesNotExist { | ||
fputs("Base path does not exist", stderr) | ||
exit(1) | ||
} catch { | ||
fputs("\(error)\n", stderr) | ||
exit(1) | ||
} |
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,43 @@ | ||
import Foundation | ||
|
||
func DownloadItems(baseURL: URL, verbose: Bool) { | ||
let fileManager = FileManager.default | ||
guard let enumerator: FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: baseURL.path) else { | ||
print("Directory not found") | ||
return | ||
} | ||
|
||
while let element = enumerator.nextObject() as? String { | ||
// Build the URL that the currently iterated over element has | ||
var elementURL: URL = URL(fileURLWithPath: baseURL.path) | ||
elementURL.appendPathComponent(element) | ||
|
||
if let values = try? elementURL.resourceValues(forKeys: [.isDirectoryKey]) { | ||
if values.isDirectory! { | ||
// Element is a directory, they already exist locally, nothing to do | ||
continue | ||
} else { | ||
// Element is a file | ||
if fileIsPlaceholder(url: elementURL) { | ||
// Element is an offloaded file, download it, do not wait for download to finish | ||
if verbose { | ||
print(" Downloading \(elementURL.path)") | ||
} | ||
TriggerDownloadFromCloud(placeholder: elementURL) | ||
} else { | ||
// Elemint is a .DS_Store file | ||
if elementURL.lastPathComponent == ".DS_Store" { | ||
if verbose { | ||
print(" Deleting \(elementURL.path)") | ||
} | ||
DeleteItems(items: [elementURL]) | ||
continue | ||
} | ||
|
||
// Element is an already downloaded file, nothing to do | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
import Foundation | ||
|
||
enum ArgumentError: Error { | ||
case BaseUnset | ||
case BaseDoesNotExist | ||
} | ||
|
||
struct CLI { | ||
private let options: IcloudoffloadOptions | ||
private let version: String | ||
|
||
init(options: IcloudoffloadOptions, version: String) { | ||
self.options = options | ||
self.version = version | ||
} | ||
|
||
func run() throws { | ||
if options.version == true { | ||
print("Version " + self.version) | ||
return | ||
} | ||
|
||
var baseUrl: URL? | ||
let fileManager = FileManager.default | ||
var isDir : ObjCBool = true | ||
|
||
if options.base == "" { | ||
throw ArgumentError.BaseUnset | ||
} else { | ||
if fileManager.fileExists(atPath: options.base, isDirectory: &isDir) { | ||
baseUrl = URL(fileURLWithPath: options.base) | ||
} else { | ||
throw ArgumentError.BaseDoesNotExist | ||
} | ||
} | ||
|
||
if let safeBaseUrl = baseUrl { | ||
OffloadItems(baseURL: safeBaseUrl, verbose: options.verbose) | ||
} | ||
} | ||
} |
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,24 @@ | ||
import Foundation | ||
import ArgumentParser | ||
|
||
struct IcloudoffloadOptions: ParsableArguments { | ||
@Flag(name: .long, help: "Print version and exit.") var version = false | ||
@Flag(name: .long, help: "Show the paths of all offloaded files.") var verbose = false | ||
@Option(help: ArgumentHelp("Set the base path.", valueName: "path")) var base = "" | ||
// --help is automatically included | ||
} | ||
|
||
let cli = CLI(options: IcloudoffloadOptions.parseOrExit(), version: "1.4.0") | ||
|
||
do { | ||
try cli.run() | ||
} catch ArgumentError.BaseUnset { | ||
fputs("Base path must be set (--base <path>)", stderr) | ||
exit(1) | ||
} catch ArgumentError.BaseDoesNotExist { | ||
fputs("Base path does not exist", stderr) | ||
exit(1) | ||
} catch { | ||
fputs("\(error)\n", stderr) | ||
exit(1) | ||
} |
Oops, something went wrong.