Revert relativePath
This commit is contained in:
parent
10aef55dad
commit
e3b3750ef0
1 changed files with 8 additions and 37 deletions
|
|
@ -50,43 +50,14 @@ proc mvFile*(source, dest: string) =
|
|||
cpFile(source, dest, move=true)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
|
||||
proc relativePath*(path, base: string; sep = DirSep): string =
|
||||
## Copied from `os.relativePath` ; remove after nim >= 0.19.9
|
||||
if path.len == 0: return ""
|
||||
var f, b: PathIter
|
||||
var ff = (0, -1)
|
||||
var bb = (0, -1) # (int, int)
|
||||
result = newStringOfCap(path.len)
|
||||
while f.hasNext(path) and b.hasNext(base):
|
||||
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 relativePath*(file, base: string): string =
|
||||
## naive version of `os.relativePath` ; remove after nim >= 0.19.9
|
||||
runnableExamples:
|
||||
doAssert "/foo/bar/baz/log.txt".relativePath("/foo/bar") == "baz/log.txt"
|
||||
var base = base
|
||||
if not base.endsWith "/": base.add "/"
|
||||
doAssert file.startsWith base
|
||||
result = file[base.len .. ^1]
|
||||
|
||||
proc extractZip*(zipfile, outdir: string) =
|
||||
var cmd = "unzip -o $#"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue