Debian Codegraph @

modules/lsp-runtime-lib/src/main/resource/DirLoader.cpp

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 23 окт. 2020 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/resource/DirLoader.h>
23
24 namespace lsp
25 {
26 namespace resource
27 {
28 DirLoader::DirLoader()
29 {
30 bEnforce = true;
31 }
32
33 DirLoader::~DirLoader()
34 {
35 }
36
37 status_t DirLoader::set_path(const char *path)
38 {
39 return sPath.set(path);
40 }
41
42 status_t DirLoader::set_path(const LSPString *path)
43 {
44 return sPath.set(path);
45 }
46
47 status_t DirLoader::set_path(const io::Path *path)
48 {
49 return sPath.set(path);
50 }
51
52 bool DirLoader::set_enforce(bool enforce)
53 {
54 bool old = bEnforce;
55 bEnforce = enforce;
56 return old;
57 }
58
59 status_t DirLoader::build_path(io::Path *dst, const io::Path *name)
60 {
61 status_t res = dst->set(name);
62 if (res == STATUS_OK)
63 res = dst->canonicalize();
64 if (res == STATUS_OK)
65 res = dst->remove_root();
66 if (res == STATUS_OK)
67 res = dst->set_parent(&sPath);
68 return res;
69 }
70
71 io::IInStream *DirLoader::read_stream(const io::Path *name)
72 {
73 if (!bEnforce)
74 return ILoader::read_stream(name);
75
76 io::Path tmp;
77 nError = build_path(&tmp, name);
78
79 return (nError == STATUS_OK) ? ILoader::read_stream(&tmp) : NULL;
80 }
81
82 ssize_t DirLoader::enumerate(const io::Path *path, resource_t **list)
83 {
84 if (!bEnforce)
85 return ILoader::enumerate(path, list);
86
87 io::Path tmp;
88 nError = build_path(&tmp, path);
89
90 return (nError == STATUS_OK) ? ILoader::enumerate(&tmp, list) : -set_error(nError);
91 }
92
93 } /* namespace resource */
94 } /* namespace lsp */
95
96