Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
athena
Manage
Activity
Members
Labels
Plan
Issues
38
Issue boards
Milestones
Wiki
Code
Merge requests
34
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIC
detectors
athena
Commits
b8213add
Commit
b8213add
authored
3 years ago
by
Wouter Deconinck
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Allow for FileLoader to use a fs::recursive_directory_iterator to find the cached file"
parent
854b17c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!329
Master into deathvalley
,
!320
Resolve "Allow for FileLoader to use a fs::recursive_directory_iterator to find the cached file"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/FileLoader.cpp
+34
-24
34 additions, 24 deletions
src/FileLoader.cpp
with
34 additions
and
24 deletions
src/FileLoader.cpp
+
34
−
24
View file @
b8213add
...
@@ -100,35 +100,45 @@ long load_file(
...
@@ -100,35 +100,45 @@ long load_file(
return
0
;
return
0
;
}
}
// if hash does not exist, we
must
retrieve file from cache
or url
// if hash does not exist, we
try to
retrieve file from cache
if
(
!
fs
::
exists
(
hash_path
))
{
if
(
!
fs
::
exists
(
hash_path
))
{
// recursive loop into cache directory
fs
::
path
cache_path
(
cache
);
fs
::
path
cache_path
(
cache
);
fs
::
path
cache_hash_path
(
cache_path
/
hash
);
printout
(
INFO
,
"FileLoader"
,
"Cache "
+
cache_path
.
string
());
if
(
fs
::
exists
(
cache_hash_path
))
{
if
(
fs
::
exists
(
cache_path
))
{
// if cache/hash exists
for
(
auto
const
&
dir_entry
:
fs
::
recursive_directory_iterator
(
cache_path
))
{
// symlink hash to cache/hash
if
(
!
dir_entry
.
is_directory
())
continue
;
printout
(
INFO
,
"FileLoader"
,
"File "
+
file
+
" with hash "
+
hash
+
" found in "
+
cache
);
fs
::
path
cache_dir_path
=
cache_path
/
dir_entry
;
try
{
printout
(
INFO
,
"FileLoader"
,
"Checking "
+
cache_dir_path
.
string
());
fs
::
create_symlink
(
cache_hash_path
,
hash_path
);
fs
::
path
cache_hash_path
=
cache_dir_path
/
hash
;
}
catch
(
const
fs
::
filesystem_error
&
)
{
if
(
fs
::
exists
(
cache_hash_path
))
{
printout
(
ERROR
,
"FileLoader"
,
"unable to link from "
+
hash_path
.
string
()
+
" to "
+
cache_hash_path
.
string
());
// symlink hash to cache/.../hash
printout
(
ERROR
,
"FileLoader"
,
"check permissions and retry"
);
printout
(
INFO
,
"FileLoader"
,
"File "
+
file
+
" with hash "
+
hash
+
" found in "
+
cache_hash_path
.
string
());
std
::
quick_exit
(
1
);
try
{
}
fs
::
create_symlink
(
cache_hash_path
,
hash_path
);
}
else
{
}
catch
(
const
fs
::
filesystem_error
&
)
{
// if cache/hash doesn't exists
printout
(
ERROR
,
"FileLoader"
,
"unable to link from "
+
hash_path
.
string
()
+
" to "
+
cache_hash_path
.
string
());
cmd
=
fmt
::
format
(
cmd
,
url
,
hash_path
.
c_str
());
// TODO: Use c++20 std::fmt
printout
(
ERROR
,
"FileLoader"
,
"check permissions and retry"
);
printout
(
INFO
,
"FileLoader"
,
"Downloading "
+
file
+
" as hash "
+
hash
+
" with "
+
cmd
);
std
::
quick_exit
(
1
);
// run cmd
}
auto
ret
=
std
::
system
(
cmd
.
c_str
());
break
;
if
(
!
fs
::
exists
(
hash_path
))
{
}
printout
(
ERROR
,
"FileLoader"
,
"unable to run cmd "
+
cmd
);
printout
(
ERROR
,
"FileLoader"
,
"check command and retry"
);
std
::
quick_exit
(
1
);
}
}
}
}
}
}
// hash_path now exists
// if hash does not exist, we try to retrieve file from url
if
(
!
fs
::
exists
(
hash_path
))
{
cmd
=
fmt
::
format
(
cmd
,
url
,
hash_path
.
c_str
());
// TODO: Use c++20 std::fmt
printout
(
INFO
,
"FileLoader"
,
"Downloading "
+
file
+
" as hash "
+
hash
+
" with "
+
cmd
);
// run cmd
auto
ret
=
std
::
system
(
cmd
.
c_str
());
if
(
!
fs
::
exists
(
hash_path
))
{
printout
(
ERROR
,
"FileLoader"
,
"unable to run cmd "
+
cmd
);
printout
(
ERROR
,
"FileLoader"
,
"check command and retry"
);
std
::
quick_exit
(
1
);
}
}
// check if file already exists
// check if file already exists
if
(
fs
::
exists
(
file_path
))
{
if
(
fs
::
exists
(
file_path
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment