aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-08-02 20:49:50 -0500
committerGanesh Viswanathan <dev@genotrance.com>2018-08-02 20:49:50 -0500
commit2c3cc71540f94783a98f34a82afc5c40bf320dd3 (patch)
tree8a71ac25b43ee30f6e302686b059113fd3dafbd7 /src
parentdc9943a22c9c8f6a5a6a92f0055e1de4dfaf87d2 (diff)
downloadnimgen-2c3cc71540f94783a98f34a82afc5c40bf320dd3.tar.gz
nimgen-2c3cc71540f94783a98f34a82afc5c40bf320dd3.zip
Fix permission denied and file flushing issues
Diffstat (limited to 'src')
-rw-r--r--src/nimgen/c2nim.nim4
-rw-r--r--src/nimgen/external.nim26
-rw-r--r--src/nimgen/file.nim10
-rw-r--r--src/nimgen/runcfg.nim2
4 files changed, 19 insertions, 23 deletions
diff --git a/src/nimgen/c2nim.nim b/src/nimgen/c2nim.nim
index f171e8d..428c767 100644
--- a/src/nimgen/c2nim.nim
+++ b/src/nimgen/c2nim.nim
@@ -20,10 +20,10 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
var cfile = file
if c2nimConfig.preprocess:
cfile = "temp-$#.c" % [outfile.extractFilename()]
- writeFile(cfile, runPreprocess(file, c2nimConfig.ppflags, c2nimConfig.flags, c2nimConfig.inline))
+ writeFileFlush(cfile, runPreprocess(file, c2nimConfig.ppflags, c2nimConfig.flags, c2nimConfig.inline))
elif c2nimConfig.ctags:
cfile = "temp-$#.c" % [outfile.extractFilename()]
- writeFile(cfile, runCtags(file))
+ writeFileFlush(cfile, runCtags(file))
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
prepend(cfile, getDefines(file, c2nimConfig.inline))
diff --git a/src/nimgen/external.nim b/src/nimgen/external.nim
index c0d5fdc..9575c38 100644
--- a/src/nimgen/external.nim
+++ b/src/nimgen/external.nim
@@ -6,22 +6,11 @@ proc sanitizePath*(path: string): string =
path.multiReplace([("\\", "/"), ("//", "/")])
proc execProc*(cmd: string): string =
- result = ""
- var
- p = startProcess(cmd, options = {poStdErrToStdOut, poUsePath, poEvalCommand})
-
- outp = outputStream(p)
- line = newStringOfCap(120).TaintedString
-
- while true:
- if outp.readLine(line):
- result.add(line)
- result.add("\n")
- elif not running(p): break
+ var ret: int
- var x = p.peekExitCode()
- if x != 0:
- echo "Command failed: " & $x
+ (result, ret) = execCmdEx(cmd)
+ if ret != 0:
+ echo "Command failed: " & $ret
echo cmd
echo result
quit(1)
@@ -64,12 +53,15 @@ proc gitReset*() =
discard execProc("git reset --hard HEAD")
proc gitCheckout*(file: string) =
- echo " Resetting " & file
+ echo "Resetting " & file
setCurrentDir(gOutput)
defer: setCurrentDir(gProjectDir)
- discard execProc("git checkout $#" % file.replace(gOutput & "/", ""))
+ let cmd = "git checkout $#" % file.replace(gOutput & "/", "")
+ if execCmdEx(cmd)[0].contains("Permission denied"):
+ sleep(500)
+ discard execProc(cmd)
proc gitRemotePull*(url: string, pull=true) =
if dirExists(gOutput/".git"):
diff --git a/src/nimgen/file.nim b/src/nimgen/file.nim
index 708ae4a..edf39ea 100644
--- a/src/nimgen/file.nim
+++ b/src/nimgen/file.nim
@@ -82,6 +82,12 @@ proc openRetry*(file: string, mode: FileMode = fmRead): File =
except IOError:
sleep(100)
+template writeFileFlush*(file, content: string): untyped =
+ let f = openRetry(file, fmWrite)
+ f.write(content)
+ f.flushFile()
+ f.close()
+
template withFile*(file: string, body: untyped): untyped =
if fileExists(file):
var f = openRetry(file)
@@ -93,9 +99,7 @@ template withFile*(file: string, body: untyped): untyped =
body
if content != contentOrig:
- f = openRetry(file, fmWrite)
- write(f, content)
- f.close()
+ writeFileFlush(file, content)
else:
echo "Missing file " & file
diff --git a/src/nimgen/runcfg.nim b/src/nimgen/runcfg.nim
index 03c0013..95cb1c4 100644
--- a/src/nimgen/runcfg.nim
+++ b/src/nimgen/runcfg.nim
@@ -57,7 +57,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
if action == "create":
echo "Creating " & file
createDir(file.splitPath().head)
- writeFile(file, cfg[act])
+ writeFileFlush(file, cfg[act])
if file in gExcludes:
gExcludes.delete(gExcludes.find(file))
sfile = search(file)