Skip to content

Commit 2a2eb36

Browse files
committed
fix path issues
1 parent 2aa7fd1 commit 2a2eb36

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/AGNI.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ module AGNI
173173

174174
# check if this is a dangerous path
175175
if !paths.is_safe_dir(out_path)
176-
error("Output directory is unsafe; cannot be used!")
176+
error("Output directory is unsafe; cannot be used!\n Got: $out_path")
177177
end
178178

179179
# looks good

src/interface/paths.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module paths
44
using LoggingExtras
55

66
# AGNI root directory (constant)
7-
const ROOT_DIR::String = abspath(dirname(abspath(@__FILE__)), "..", "..")
7+
const ROOT_DIR::String = normpath(abspath(dirname(abspath(@__FILE__)), "..", ".."))
88
export ROOT_DIR
99

1010
# Resources directory (constant)
11-
const RES_DIR::String = joinpath(ROOT_DIR, "res")
11+
const RES_DIR::String = normpath(joinpath(ROOT_DIR, "res"))
1212
export RES_DIR
1313

1414
# FWL_DATA folder (fall back to RES_DIR if not set)
15-
const FWL_DATA::String = joinpath(get(ENV, "FWL_DATA", RES_DIR))
15+
const FWL_DATA::String = normpath(joinpath(get(ENV, "FWL_DATA", RES_DIR)))
1616
export FWL_DATA
1717

1818
"""
@@ -62,28 +62,30 @@ module paths
6262
"""
6363
function is_safe_dir(path::String)::Bool
6464
# Do not allow empty paths
65-
!isempty(path) || return false
65+
isempty(path) && return false
6666

6767
# Normalise path for other checks...
68-
path = abspath(path)
68+
path = normpath(abspath(path))
6969

7070
# Contains git repo
7171
ispath(joinpath(path, ".git")) && return false
7272

7373
# Is current working directory
74-
(joinpath(path) == pwd()) && return false
74+
(path == pwd()) && return false
7575

7676
# Is system root directory
77-
(path == "/") && return false
77+
(path == normpath("/")) && return false
7878

7979
# Is user home directory
8080
(path == homedir()) && return false
8181

8282
# Is AGNI root directory
83-
(path == abspath(paths.ROOT_DIR)) && return false
83+
(path == paths.ROOT_DIR) && return false
8484

8585
# Is AGNI resources directory
86-
(path == abspath(paths.RES_DIR)) && return false
86+
(path == paths.RES_DIR) && return false
87+
88+
return true
8789
end
8890
export is_safe_dir
8991

0 commit comments

Comments
 (0)