diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-10-01 11:33:24 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-10-02 15:32:03 -0500 |
| commit | 86aea481ac3433ddeae7832fc9749f99e12d5f7b (patch) | |
| tree | edd6cf509884842d8b90443ec42adfb567c0114f | |
| parent | fad9fd78f30eda750e615f69dd88f28158effbce (diff) | |
| download | nimterop-86aea481ac3433ddeae7832fc9749f99e12d5f7b.tar.gz nimterop-86aea481ac3433ddeae7832fc9749f99e12d5f7b.zip | |
Add retries for file ops
| -rw-r--r-- | nimterop/build.nim | 15 | ||||
| -rw-r--r-- | tests/lzma.nim | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim index 24ae87c..e36324a 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -9,7 +9,7 @@ proc sanitizePath*(path: string, noQuote = false, sep = $DirSep): string = if not noQuote: result = result.quoteShell -proc execAction*(cmd: string, nostderr=false): string = +proc execAction*(cmd: string, retry = 0, nostderr = false): string = ## Execute an external command - supported at compile time ## ## Checks if command exits successfully before returning. If not, an @@ -29,7 +29,12 @@ proc execAction*(cmd: string, nostderr=false): string = else: let opt = if nostderr: {poUsePath} else: {poStdErrToStdOut, poUsePath} (result, ret) = execCmdEx(ccmd, opt) - doAssert ret == 0, "Command failed: " & $(ret, nostderr) & "\nccmd: " & ccmd & "\nresult:\n" & result + if ret != 0: + if retry > 0: + sleep(500) + result = execAction(cmd, retry = retry - 1) + else: + doAssert true, "Command failed: " & $(ret, nostderr) & "\nccmd: " & ccmd & "\nresult:\n" & result proc findExe*(exe: string): string = ## Find the specified executable using the `which`/`where` command - supported @@ -54,7 +59,7 @@ proc mkDir*(dir: string) = if not dirExists(dir): let flag = when not defined(Windows): "-p" else: "" - discard execAction(&"mkdir {flag} {dir.sanitizePath}") + discard execAction(&"mkdir {flag} {dir.sanitizePath}", retry = 2) proc cpFile*(source, dest: string, move=false) = ## Copy a file from `source` to `dest` at compile time @@ -73,7 +78,7 @@ proc cpFile*(source, dest: string, move=false) = else: "cp -f" - discard execAction(&"{cmd} {source.sanitizePath} {dest.sanitizePath}") + discard execAction(&"{cmd} {source.sanitizePath} {dest.sanitizePath}", retry = 2) proc mvFile*(source, dest: string) = ## Move a file from `source` to `dest` at compile time @@ -92,7 +97,7 @@ proc rmFile*(source: string, dir = false) = else: "rm -rf" - discard execAction(&"{cmd} {source.sanitizePath}") + discard execAction(&"{cmd} {source.sanitizePath}", retry = 2) proc rmDir*(source: string) = ## Remove a directory or pattern at compile time diff --git a/tests/lzma.nim b/tests/lzma.nim index 32f9fa0..2368b55 100644 --- a/tests/lzma.nim +++ b/tests/lzma.nim @@ -3,7 +3,7 @@ import os, strutils import nimterop/[build, cimport] const - baseDir = currentSourcePath.parentDir()/"build/liblzma" + baseDir = currentSourcePath.parentDir()/"build"/"liblzma" static: cDebug() |
