Adds option to exclude nimcache dirs from time machine backups.
This commit is contained in:
parent
3670fe2385
commit
1c89c45ae9
2 changed files with 27 additions and 1 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import
|
import
|
||||||
os, lists, strutils, strtabs
|
os, lists, strutils, strtabs, osproc, sets
|
||||||
|
|
||||||
const
|
const
|
||||||
hasTinyCBackend* = defined(tinyc)
|
hasTinyCBackend* = defined(tinyc)
|
||||||
|
|
@ -16,6 +16,7 @@ const
|
||||||
hasFFI* = defined(useFFI)
|
hasFFI* = defined(useFFI)
|
||||||
newScopeForIf* = true
|
newScopeForIf* = true
|
||||||
useCaas* = not defined(noCaas)
|
useCaas* = not defined(noCaas)
|
||||||
|
noTimeMachine = defined(avoidTimeMachine) and defined(macosx)
|
||||||
|
|
||||||
type # please make sure we have under 32 options
|
type # please make sure we have under 32 options
|
||||||
# (improves code efficiency a lot!)
|
# (improves code efficiency a lot!)
|
||||||
|
|
@ -263,6 +264,28 @@ proc toGeneratedFile*(path, ext: string): string =
|
||||||
result = joinPath([getGeneratedPath(), changeFileExt(tail, ext)])
|
result = joinPath([getGeneratedPath(), changeFileExt(tail, ext)])
|
||||||
#echo "toGeneratedFile(", path, ", ", ext, ") = ", result
|
#echo "toGeneratedFile(", path, ", ", ext, ") = ", result
|
||||||
|
|
||||||
|
when noTimeMachine:
|
||||||
|
var alreadyExcludedDirs = initSet[string]()
|
||||||
|
proc excludeDirFromTimeMachine(dir: string) {.raises: [].} =
|
||||||
|
## Calls a macosx command on the directory to exclude it from backups.
|
||||||
|
##
|
||||||
|
## The macosx tmutil command is invoked to mark the specified path as an
|
||||||
|
## item to be excluded from time machine backups. If a path already exists
|
||||||
|
## with files before excluding it, newer files won't be added to the
|
||||||
|
## directory, but previous files won't be removed from the backup until the
|
||||||
|
## user deletes that directory.
|
||||||
|
##
|
||||||
|
## The whole proc is optional and will ignore all kinds of errors. The only
|
||||||
|
## way to be sure that it works is to call ``tmutil isexcluded path``.
|
||||||
|
if alreadyExcludedDirs.contains(dir): return
|
||||||
|
alreadyExcludedDirs.incl(dir)
|
||||||
|
try:
|
||||||
|
var p = startProcess("/usr/bin/tmutil", args = ["addexclusion", dir])
|
||||||
|
discard p.waitForExit
|
||||||
|
p.close
|
||||||
|
except E_Base, EOS:
|
||||||
|
discard
|
||||||
|
|
||||||
proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
|
proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
|
||||||
var (head, tail) = splitPath(f)
|
var (head, tail) = splitPath(f)
|
||||||
#if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep))
|
#if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep))
|
||||||
|
|
@ -270,6 +293,8 @@ proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
|
||||||
if createSubDir:
|
if createSubDir:
|
||||||
try:
|
try:
|
||||||
createDir(subdir)
|
createDir(subdir)
|
||||||
|
when noTimeMachine:
|
||||||
|
excludeDirFromTimeMachine(subdir)
|
||||||
except EOS:
|
except EOS:
|
||||||
writeln(stdout, "cannot create directory: " & subdir)
|
writeln(stdout, "cannot create directory: " & subdir)
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
|
||||||
1
koch.nim
1
koch.nim
|
|
@ -53,6 +53,7 @@ Boot options:
|
||||||
(not needed on Windows)
|
(not needed on Windows)
|
||||||
-d:nativeStacktrace use native stack traces (only for Mac OS X or Linux)
|
-d:nativeStacktrace use native stack traces (only for Mac OS X or Linux)
|
||||||
-d:noCaas build Nimrod without CAAS support
|
-d:noCaas build Nimrod without CAAS support
|
||||||
|
-d:avoidTimeMachine only for Mac OS X, excludes nimcache dir from backups
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc exe(f: string): string = return addFileExt(f, ExeExt)
|
proc exe(f: string): string = return addFileExt(f, ExeExt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue