Skip to content

Commit 37f091b

Browse files
committed
better fuzzy search for tar
1 parent f5733fd commit 37f091b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/FileDFG/services/FileDFG.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,27 @@ ls(dfg)
7676
```
7777
"""
7878
function loadDFG(dst::String, iifModule, dfgLoadInto::G; loaddir=joinpath("/","tmp","caesar","random")) where G <: AbstractDFG
79-
# Check if zipped destination (dst)
80-
@show folder = isdir(dst) ? dst : (dst*".tar.gz")
81-
sfolder = split(folder, '.')
82-
if sfolder[end] == "gz" && sfolder[end-1] == "tar"
83-
Base.mkpath(loaddir)
84-
@show folder = joinpath(loaddir, splitpath(string(sfolder[end-2]))[end] )
85-
@info "loadDF detected a gzip tarball -- unpacking via $folder now..."
86-
Base.rm(folder, recursive=true, force=true)
87-
# unzip the tar file
88-
run(`tar -zxf $dst -C $loaddir`)
79+
# Check if zipped destination (dst) by first doing fuzzy search from user supplied dst (might not have .tar.gz extension)
80+
folder = dst
81+
unzip = false
82+
sdst = split(folder, '.')
83+
if !isdir(dst)
84+
unzip = true
85+
if sdst[end] != "gz" && sdst[end-1] != "tar"
86+
folder *= ".tar.gz"
87+
end
8988
end
89+
# do actual unzipping
90+
if unzip
91+
sfolder = split(folder, '.')
92+
Base.mkpath(loaddir)
93+
@show folder = joinpath(loaddir, splitpath(string(sfolder[end-2]))[end] )
94+
@info "loadDF detected a gzip tarball -- unpacking via $folder now..."
95+
Base.rm(folder, recursive=true, force=true)
96+
# unzip the tar file
97+
run(`tar -zxf $dst -C $loaddir`)
98+
end
99+
# extract the factor graph from fileDFG folder
90100
variables = DFGVariable[]
91101
factors = DFGFactor[]
92102
varFolder = "$folder/variables"

0 commit comments

Comments
 (0)