Revert relativePath

This commit is contained in:
Ganesh Viswanathan 2019-02-06 15:10:19 -06:00
commit e3b3750ef0

View file

@ -50,43 +50,14 @@ proc mvFile*(source, dest: string) =
cpFile(source, dest, move=true) cpFile(source, dest, move=true)
when (NimMajor, NimMinor, NimPatch) < (0, 19, 9): when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
proc relativePath*(path, base: string; sep = DirSep): string = proc relativePath*(file, base: string): string =
## Copied from `os.relativePath` ; remove after nim >= 0.19.9 ## naive version of `os.relativePath` ; remove after nim >= 0.19.9
if path.len == 0: return "" runnableExamples:
var f, b: PathIter doAssert "/foo/bar/baz/log.txt".relativePath("/foo/bar") == "baz/log.txt"
var ff = (0, -1) var base = base
var bb = (0, -1) # (int, int) if not base.endsWith "/": base.add "/"
result = newStringOfCap(path.len) doAssert file.startsWith base
while f.hasNext(path) and b.hasNext(base): result = file[base.len .. ^1]
ff = next(f, path)
bb = next(b, base)
let diff = ff[1] - ff[0]
if diff != bb[1] - bb[0]: break
var same = true
for i in 0..diff:
if path[i + ff[0]] !=? base[i + bb[0]]:
same = false
break
if not same: break
ff = (0, -1)
bb = (0, -1)
while true:
if bb[1] >= bb[0]:
if result.len > 0 and result[^1] != sep:
result.add sep
result.add ".."
if not b.hasNext(base): break
bb = b.next(base)
while true:
if ff[1] >= ff[0]:
if result.len > 0 and result[^1] != sep:
result.add sep
for i in 0..ff[1] - ff[0]:
result.add path[i + ff[0]]
if not f.hasNext(path): break
ff = f.next(path)
proc extractZip*(zipfile, outdir: string) = proc extractZip*(zipfile, outdir: string) =
var cmd = "unzip -o $#" var cmd = "unzip -o $#"