Debian Codegraph @

src/core/filecache.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/filecache.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "filecache.h"cxx . . $ `<file>/src/core/filecache.h`/
5
6 #include "common/fileutils.h"cxx . . $ `<file>/src/common/fileutils.h`/
7 #include <exception>
8 #include <format>
9 #include <spdlog/spdlog.h>
10 #include <stdexcept>
11 #include <utility>
12
13 namespace fs = stdcxx . . $ std/::filesystem;
14
15 FileCachecxx . . $ FileCache#::FileCachecxx . . $ FileCache#FileCache(91601bf9ad65ca31).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &&path) noexcept
16 : path_cxx . . $ FileCache#path_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(path))
17 {
18 }
19
20 void FileCachecxx . . $ FileCache#::initcxx . . $ FileCache#init(49f6e7a06ebc5aa8).()
21 {
22 if (!fs::existscxx . . $ std/filesystem/exists(c53a6ef3278968b1).(path_cxx . . $ FileCache#path_.)) {
23 fs::create_directoriescxx . . $ std/filesystem/create_directories(c53a6ef3278968b1).(path_cxx . . $ FileCache#path_.);
24 fs::permissionscxx . . $ std/filesystem/permissions(b42180d75ff20d25).(path_cxx . . $ FileCache#path_., fs::permscxx . . $ std/filesystem/perms#::owner_allcxx . . $ std/filesystem/perms#owner_all. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). fs::permscxx . . $ std/filesystem/perms#::group_readcxx . . $ std/filesystem/perms#group_read. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25).
25 fs::permscxx . . $ std/filesystem/perms#::group_execcxx . . $ std/filesystem/perms#group_exec. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). fs::permscxx . . $ std/filesystem/perms#::others_readcxx . . $ std/filesystem/perms#others_read. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25).
26 fs::permscxx . . $ std/filesystem/perms#::others_execcxx . . $ std/filesystem/perms#others_exec.);
27 }
28
29 if (!fs::is_directorycxx . . $ std/filesystem/is_directory(c53a6ef3278968b1).(path_cxx . . $ FileCache#path_.))
30 throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#(
31 stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("{} is not a directory."cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., path_cxx . . $ FileCache#path_..c_strcxx . . $ std/filesystem/__cxx11/path#c_str(ba32b354807b2b81).()));
32 }
33
34 stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#>
35 FileCachecxx . . $ FileCache#::addcxx . . $ FileCache#add(efab1f07c9a586fc).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &path, stdcxx . . $ std/::stringcxx . . $ std/string# const &name)
36 {
37 if (cacheDirectoryExistcxx . . $ FileCache#cacheDirectoryExist(50ce9a9e25b4a850).()) {
38 if (Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::isFilePathValidcxx . . $ Utils/File/isFilePathValid(c53a6ef3278968b1).(path)) {
39 auto target = path_cxx . . $ FileCache#path_. /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). namecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).;
40 if (path != target) {
41 try {
42 fs::copy_filecxx . . $ std/filesystem/copy_file(a0213926d45dbebc).(path, target, fs::copy_optionscxx . . $ std/filesystem/copy_options#::overwrite_existingcxx . . $ std/filesystem/copy_options#overwrite_existing.);
43 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24).target};
44 }
45 catch (stdcxx . . $ std/::exception const &e) {
46 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
47 }
48 }
49 else // file is on cache
50 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24).target};
51 }
52 else
53 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot add {} to cache. Invalid or missing file.",
54 path.c_str());
55 }
56
57 return {cxx . . $ std/optional#optional(ced63f7c635d850d).};
58 }
59
60 stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#>
61 FileCachecxx . . $ FileCache#::addcxx . . $ FileCache#add(d83eed0e64cf1041).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<char> const &data, stdcxx . . $ std/::stringcxx . . $ std/string# const &name)
62 {
63 if (cacheDirectoryExistcxx . . $ FileCache#cacheDirectoryExist(50ce9a9e25b4a850).()) {
64 auto target = path_cxx . . $ FileCache#path_. /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). namecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).;
65 if (Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::writeFilecxx . . $ Utils/File/writeFile(231cf0731af4b996).(target, data))
66 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24).target};
67 }
68
69 return {cxx . . $ std/optional#optional(ced63f7c635d850d).};
70 }
71
72 void FileCachecxx . . $ FileCache#::removecxx . . $ FileCache#remove(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &name)
73 {
74 if (cacheDirectoryExistcxx . . $ FileCache#cacheDirectoryExist(50ce9a9e25b4a850).()) {
75 auto target = path_cxx . . $ FileCache#path_. /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). namecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).;
76 try {
77 fs::removecxx . . $ std/filesystem/remove(c53a6ef3278968b1).(target);
78 }
79 catch (stdcxx . . $ std/::exception const &e) {
80 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
81 }
82 }
83 }
84
85 stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#>
86 FileCachecxx . . $ FileCache#::getcxx . . $ FileCache#get(e718be3153167360).(stdcxx . . $ std/::stringcxx . . $ std/string# const &name,
87 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &defaultPath) const
88 {
89 if (cacheDirectoryExistcxx . . $ FileCache#cacheDirectoryExist(50ce9a9e25b4a850).()) {
90 auto target = path_cxx . . $ FileCache#path_. /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). namecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).;
91 if (Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::isFilePathValidcxx . . $ Utils/File/isFilePathValid(c53a6ef3278968b1).(target))
92 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24).target};
93 else
94 SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("Cannot get {} from cache. Invalid or missing file.",
95 target.c_str());
96 }
97
98 if (!defaultPath.emptycxx . . $ std/filesystem/__cxx11/path#empty(3482b152b9333168).())
99 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24).defaultPath};
100 else
101 return {cxx . . $ std/optional#optional(ced63f7c635d850d).};
102 }
103
104 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# FileCachecxx . . $ FileCache#::pathcxx . . $ FileCache#path(159787a050b29eb0).() const
105 {
106 return path_cxx . . $ std/filesystem/__cxx11/path#path(3f42e2c2fac0d5fc).;
107 }
108
109 bool FileCachecxx . . $ FileCache#::cacheDirectoryExistcxx . . $ FileCache#cacheDirectoryExist(50ce9a9e25b4a850).() const
110 {
111 if (Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::isDirectoryPathValidcxx . . $ Utils/File/isDirectoryPathValid(c53a6ef3278968b1).(path_cxx . . $ FileCache#path_.))
112 return true;
113
114 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Missing or invalid cache directory {}", path_.c_str());
115 return false;
116 }