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
|
||||
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))
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
var ret: int
|
||||
|
||||
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 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"):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue