Fix permission denied and file flushing issues
This commit is contained in:
parent
dc9943a22c
commit
2c3cc71540
4 changed files with 19 additions and 23 deletions
|
|
@ -20,10 +20,10 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
var cfile = file
|
var cfile = file
|
||||||
if c2nimConfig.preprocess:
|
if c2nimConfig.preprocess:
|
||||||
cfile = "temp-$#.c" % [outfile.extractFilename()]
|
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:
|
elif c2nimConfig.ctags:
|
||||||
cfile = "temp-$#.c" % [outfile.extractFilename()]
|
cfile = "temp-$#.c" % [outfile.extractFilename()]
|
||||||
writeFile(cfile, runCtags(file))
|
writeFileFlush(cfile, runCtags(file))
|
||||||
|
|
||||||
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
||||||
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,11 @@ proc sanitizePath*(path: string): string =
|
||||||
path.multiReplace([("\\", "/"), ("//", "/")])
|
path.multiReplace([("\\", "/"), ("//", "/")])
|
||||||
|
|
||||||
proc execProc*(cmd: string): string =
|
proc execProc*(cmd: string): string =
|
||||||
result = ""
|
var ret: int
|
||||||
var
|
|
||||||
p = startProcess(cmd, options = {poStdErrToStdOut, poUsePath, poEvalCommand})
|
|
||||||
|
|
||||||
outp = outputStream(p)
|
(result, ret) = execCmdEx(cmd)
|
||||||
line = newStringOfCap(120).TaintedString
|
if ret != 0:
|
||||||
|
echo "Command failed: " & $ret
|
||||||
while true:
|
|
||||||
if outp.readLine(line):
|
|
||||||
result.add(line)
|
|
||||||
result.add("\n")
|
|
||||||
elif not running(p): break
|
|
||||||
|
|
||||||
var x = p.peekExitCode()
|
|
||||||
if x != 0:
|
|
||||||
echo "Command failed: " & $x
|
|
||||||
echo cmd
|
echo cmd
|
||||||
echo result
|
echo result
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
@ -64,12 +53,15 @@ proc gitReset*() =
|
||||||
discard execProc("git reset --hard HEAD")
|
discard execProc("git reset --hard HEAD")
|
||||||
|
|
||||||
proc gitCheckout*(file: string) =
|
proc gitCheckout*(file: string) =
|
||||||
echo " Resetting " & file
|
echo "Resetting " & file
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir(gProjectDir)
|
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) =
|
proc gitRemotePull*(url: string, pull=true) =
|
||||||
if dirExists(gOutput/".git"):
|
if dirExists(gOutput/".git"):
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,12 @@ proc openRetry*(file: string, mode: FileMode = fmRead): File =
|
||||||
except IOError:
|
except IOError:
|
||||||
sleep(100)
|
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 =
|
template withFile*(file: string, body: untyped): untyped =
|
||||||
if fileExists(file):
|
if fileExists(file):
|
||||||
var f = openRetry(file)
|
var f = openRetry(file)
|
||||||
|
|
@ -93,9 +99,7 @@ template withFile*(file: string, body: untyped): untyped =
|
||||||
body
|
body
|
||||||
|
|
||||||
if content != contentOrig:
|
if content != contentOrig:
|
||||||
f = openRetry(file, fmWrite)
|
writeFileFlush(file, content)
|
||||||
write(f, content)
|
|
||||||
f.close()
|
|
||||||
else:
|
else:
|
||||||
echo "Missing file " & file
|
echo "Missing file " & file
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
|
||||||
if action == "create":
|
if action == "create":
|
||||||
echo "Creating " & file
|
echo "Creating " & file
|
||||||
createDir(file.splitPath().head)
|
createDir(file.splitPath().head)
|
||||||
writeFile(file, cfg[act])
|
writeFileFlush(file, cfg[act])
|
||||||
if file in gExcludes:
|
if file in gExcludes:
|
||||||
gExcludes.delete(gExcludes.find(file))
|
gExcludes.delete(gExcludes.find(file))
|
||||||
sfile = search(file)
|
sfile = search(file)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue