| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/files.hpp" | ||
| 30 | #include "gate/results.h" | ||
| 31 | #include "gate/utilities.h" | ||
| 32 | #include "gate/utilities.hpp" | ||
| 33 | #include "gate/exceptions.hpp" | ||
| 34 | #include "gate/strings.hpp" | ||
| 35 | |||
| 36 | namespace gate | ||
| 37 | { | ||
| 38 | enumint_t const File::Open_Read = GATE_STREAM_OPEN_READ; | ||
| 39 | enumint_t const File::Open_Write = GATE_STREAM_OPEN_WRITE; | ||
| 40 | enumint_t const File::Open_ReadWrite = GATE_STREAM_OPEN_READWRITE; | ||
| 41 | enumint_t const File::Open_Append = GATE_STREAM_OPEN_APPEND; | ||
| 42 | enumint_t const File::Open_AppendWrite = GATE_STREAM_OPEN_APPENDWRITE; | ||
| 43 | enumint_t const File::Open_AppendReadWrite = GATE_STREAM_OPEN_APPENDREADWRITE; | ||
| 44 | enumint_t const File::Open_CreateOwnerRestricted = GATE_FILE_OPEN_CREATEOWNERRESTRICTED; | ||
| 45 | enumint_t const File::Open_CreateGroupRestricted = GATE_FILE_OPEN_CREATEGROUPRESTRICTED; | ||
| 46 | enumint_t const File::Open_CreateUnrestricted = GATE_FILE_OPEN_CREATEUNRESTRICTED; | ||
| 47 | enumint_t const File::Open_CreateExecutable = GATE_FILE_OPEN_CREATEEXECUTABLE; | ||
| 48 | enumint_t const File::Open_Shared = GATE_FILE_OPEN_SHARED; | ||
| 49 | |||
| 50 | 12 | static gate_controlstream_t* open_filestream(String const& filepath, enumint_t flags) | |
| 51 | { | ||
| 52 | 12 | gate_controlstream_t* ret = NULL; | |
| 53 |
1/2✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 | result_t res = gate_file_openstream(filepath.c_impl(), flags, &ret); |
| 54 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | GATEXX_CHECK_EXCEPTION(res); |
| 55 | 12 | return ret; | |
| 56 | } | ||
| 57 | |||
| 58 | 12 | FileStream::FileStream(String const& filepath, enumint_t flags) | |
| 59 | 12 | : ControlStream(open_filestream(filepath, flags)) | |
| 60 | { | ||
| 61 | 12 | } | |
| 62 | 1 | FileStream::FileStream(FileStream const& src) | |
| 63 | 1 | : ControlStream(src) | |
| 64 | { | ||
| 65 | |||
| 66 | 1 | } | |
| 67 | 1 | FileStream& FileStream::operator=(FileStream const& src) | |
| 68 | { | ||
| 69 | 1 | Stream::operator=(src); | |
| 70 | 1 | return *this; | |
| 71 | } | ||
| 72 | 13 | FileStream::~FileStream() | |
| 73 | { | ||
| 74 | |||
| 75 | 13 | } | |
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | 10 | String File::buildPath(String const& parent, String const& subitem) | |
| 83 | { | ||
| 84 | gate_string_t tmp; | ||
| 85 |
2/4✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
|
10 | if (NULL == gate_file_build_path_string(&tmp, parent.c_impl(), subitem.c_impl())) |
| 86 | { | ||
| 87 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 88 | } | ||
| 89 | 10 | String ret(String::duplicate(tmp)); | |
| 90 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | gate_string_release(&tmp); |
| 91 | 20 | return ret; | |
| 92 | } | ||
| 93 | 3 | bool File::splitPath(String const& path, String& parent, String& subitem) | |
| 94 | { | ||
| 95 | 3 | gate_string_t parent_str = GATE_STRING_INIT_EMPTY; | |
| 96 | 3 | gate_string_t subitem_str = GATE_STRING_INIT_EMPTY; | |
| 97 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | gate_result_t result = gate_file_split_path(path.c_impl(), &parent_str, &subitem_str); |
| 98 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (GATE_SUCCEEDED(result)) |
| 99 | { | ||
| 100 | 2 | parent = String::createFrom(parent_str); | |
| 101 | 2 | subitem = String::createFrom(subitem_str); | |
| 102 | 2 | return true; | |
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | 1 | parent = String::createFrom(parent_str); | |
| 107 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | subitem = path.clone(); |
| 108 | 1 | return false; | |
| 109 | } | ||
| 110 | } | ||
| 111 | 1 | void File::extractPath(String const& path, char* name, size_t nameCapacity, char* parent, size_t parentCapacity) | |
| 112 | { | ||
| 113 | 1 | result_t result = gate_file_extract_path(path.c_str(), path.length(), name, nameCapacity, parent, parentCapacity); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 115 | 1 | } | |
| 116 | 1 | void File::extractPath(String const& path, String* name, String* parent) | |
| 117 | { | ||
| 118 | gate_string_t str_name; | ||
| 119 | gate_string_t str_parent; | ||
| 120 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | result_t result = gate_file_extract_path_string( |
| 121 | path.c_impl(), | ||
| 122 | name ? &str_name : NULL, | ||
| 123 | parent ? &str_parent : NULL); | ||
| 124 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 125 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (name) |
| 126 | { | ||
| 127 | 1 | *name = String::createFrom(str_name); | |
| 128 | } | ||
| 129 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (parent) |
| 130 | { | ||
| 131 | 1 | *parent = String::createFrom(str_parent); | |
| 132 | } | ||
| 133 | 1 | } | |
| 134 | |||
| 135 | |||
| 136 | 2 | bool_t File::getParent(String const& path, String& parent) | |
| 137 | { | ||
| 138 | 2 | gate_string_t parent_str = GATE_STRING_INIT_EMPTY; | |
| 139 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | gate_result_t result = gate_file_split_path(path.c_impl(), &parent_str, NULL); |
| 140 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (GATE_SUCCEEDED(result)) |
| 141 | { | ||
| 142 | 2 | parent = String::createFrom(parent_str); | |
| 143 | 2 | return true; | |
| 144 | } | ||
| 145 | ✗ | return false; | |
| 146 | } | ||
| 147 | 3 | bool_t File::getName(String const& path, String& name) | |
| 148 | { | ||
| 149 | 3 | gate_string_t name_str = GATE_STRING_INIT_EMPTY; | |
| 150 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | gate_result_t result = gate_file_split_path(path.c_impl(), NULL, &name_str); |
| 151 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (GATE_SUCCEEDED(result)) |
| 152 | { | ||
| 153 | 3 | name = String::createFrom(name_str); | |
| 154 | 3 | return true; | |
| 155 | } | ||
| 156 | ✗ | return false; | |
| 157 | } | ||
| 158 | |||
| 159 | 2 | String File::baseName(String const& path) | |
| 160 | { | ||
| 161 | 2 | String ret; | |
| 162 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | File::getName(path, ret); |
| 163 | 2 | return ret; | |
| 164 | } | ||
| 165 | |||
| 166 | 1 | String File::dirName(String const& path) | |
| 167 | { | ||
| 168 | 1 | String ret; | |
| 169 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | File::getParent(path, ret); |
| 170 | 1 | return ret; | |
| 171 | } | ||
| 172 | |||
| 173 | 1 | String File::realPath(String const& path) | |
| 174 | { | ||
| 175 | 1 | gate_string_t ret = GATE_STRING_INIT_EMPTY; | |
| 176 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_real_path(path.c_impl(), &ret); |
| 177 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 178 | 2 | return String::createFrom(ret); | |
| 179 | } | ||
| 180 | |||
| 181 | 1 | ControlStream File::open(String const& path, enumint_t openFlags) | |
| 182 | { | ||
| 183 | 1 | gate_controlstream_t* stream = NULL; | |
| 184 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_openstream(path.c_impl(), openFlags, &stream); |
| 185 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 186 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return ControlStream(stream); |
| 187 | } | ||
| 188 | |||
| 189 | |||
| 190 | 23 | bool File::exists(String const& filepath) | |
| 191 | { | ||
| 192 | 23 | return GATE_SUCCEEDED(gate_file_exists(filepath.c_impl())); | |
| 193 | } | ||
| 194 | 1 | void File::copy(String const& srcfilepath, String const& dstfilepath, CopyEnum flags) | |
| 195 | { | ||
| 196 | 1 | result_t const res = gate_file_copy(srcfilepath.c_impl(), dstfilepath.c_impl(), (gate_uint32_t)flags); | |
| 197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 198 | 1 | } | |
| 199 | |||
| 200 | 1 | static gate_bool_t GATE_CALL File_copyList_callback(char const* source_path, char const* dest_path, gate_result_t result, void* user_param) | |
| 201 | { | ||
| 202 | 1 | File::CopyListCallback const* const ptrCb = static_cast<File::CopyListCallback const*>(user_param); | |
| 203 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | String const source(source_path); |
| 204 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | String const dest(dest_path); |
| 205 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ptrCb->invoke(source, dest, result); |
| 206 | 2 | return true; | |
| 207 | } | ||
| 208 | |||
| 209 | 1 | void File::copyList(Map<String, String> const& fileMapping, CopyListCallback const& callback, enumint_t flags) | |
| 210 | { | ||
| 211 | 1 | result_t const result = gate_file_copy_list( | |
| 212 | fileMapping.c_impl(), flags, | ||
| 213 | &File_copyList_callback, const_cast<File::CopyListCallback*>(&callback)); | ||
| 214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 215 | 1 | } | |
| 216 | |||
| 217 | |||
| 218 | 1 | void File::move(String const& srcfilepath, String const& dstfilepath) | |
| 219 | { | ||
| 220 | 1 | result_t res = gate_file_move(srcfilepath.c_impl(), dstfilepath.c_impl()); | |
| 221 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 222 | 1 | } | |
| 223 | 4 | void File::removeFile(String const& filepath) | |
| 224 | { | ||
| 225 | 4 | result_t res = gate_file_delete(filepath.c_impl()); | |
| 226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(res); |
| 227 | 4 | } | |
| 228 | 1 | void File::createLink(String const& targetpath, String const& linkfile) | |
| 229 | { | ||
| 230 | 1 | result_t res = gate_file_create_link(targetpath.c_impl(), linkfile.c_impl()); | |
| 231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 232 | 1 | } | |
| 233 | 1 | void File::createHardLink(String const& targetpath, String const& newlinkpath) | |
| 234 | { | ||
| 235 | 1 | result_t res = gate_file_create_hardlink(targetpath.c_impl(), newlinkpath.c_impl()); | |
| 236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 237 | 1 | } | |
| 238 | 1 | String File::readLink(String const& linkfilepath) | |
| 239 | { | ||
| 240 | gate_string_t realpath; | ||
| 241 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t res = gate_file_read_link(linkfilepath.c_impl(), &realpath); |
| 242 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 243 | 2 | return String::createFrom(realpath); | |
| 244 | } | ||
| 245 | |||
| 246 | struct GATE_API_LOCAL gate_directory_list_entries_struct | ||
| 247 | { | ||
| 248 | File::callback_t delegate_cb; | ||
| 249 | void* user_param; | ||
| 250 | |||
| 251 | 2 | gate_directory_list_entries_struct(File::callback_t const& cb, void* param) | |
| 252 | 2 | : delegate_cb(cb), user_param(param) | |
| 253 | { | ||
| 254 | 2 | } | |
| 255 | }; | ||
| 256 | |||
| 257 | 20 | File::Entry::Entry() | |
| 258 | { | ||
| 259 | 20 | gate_mem_clear(static_cast<gate_file_entry_t*>(this), sizeof(gate_file_entry_t)); | |
| 260 | 20 | } | |
| 261 | |||
| 262 | 30 | File::Entry::Entry(gate_file_entry_t const& entry) | |
| 263 | { | ||
| 264 | 30 | gate_mem_copy(static_cast<gate_file_entry_t*>(this), &entry, sizeof(gate_file_entry_t)); | |
| 265 | 30 | } | |
| 266 | 1 | File::Entry::Entry(Entry const& src) | |
| 267 | { | ||
| 268 | 1 | gate_mem_copy(static_cast<gate_file_entry_t*>(this), | |
| 269 | static_cast<gate_file_entry_t const*>(&src), | ||
| 270 | sizeof(gate_file_entry_t)); | ||
| 271 | 1 | } | |
| 272 | 1 | File::Entry& File::Entry::operator=(Entry const& src) | |
| 273 | { | ||
| 274 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this != &src) |
| 275 | { | ||
| 276 | 1 | gate_mem_copy(static_cast<gate_file_entry_t*>(this), | |
| 277 | static_cast<gate_file_entry_t const*>(&src), | ||
| 278 | sizeof(gate_file_entry_t)); | ||
| 279 | } | ||
| 280 | 1 | return *this; | |
| 281 | } | ||
| 282 | |||
| 283 | 51 | File::Entry::~Entry() noexcept | |
| 284 | { | ||
| 285 | 51 | } | |
| 286 | |||
| 287 | 19 | String File::Entry::getName() const | |
| 288 | { | ||
| 289 | 19 | return String(this->name, gate_str_length(this->name)); | |
| 290 | } | ||
| 291 | 25 | String File::Entry::getPath() const | |
| 292 | { | ||
| 293 | 25 | return String(this->path, gate_str_length(this->path)); | |
| 294 | } | ||
| 295 | 2 | uint64_t File::Entry::getSize() const | |
| 296 | { | ||
| 297 | 2 | return this->props.size; | |
| 298 | } | ||
| 299 | 1 | enumint_t File::Entry::getAttributes() const | |
| 300 | { | ||
| 301 | 1 | return this->props.attribs; | |
| 302 | } | ||
| 303 | 1 | enumint_t File::Entry::getAccessBits() const | |
| 304 | { | ||
| 305 | 1 | return this->props.access; | |
| 306 | } | ||
| 307 | |||
| 308 | 1 | DateTime File::Entry::getTimeCreated(bool_t addSystemBias) const | |
| 309 | { | ||
| 310 | 1 | return DateTime(this->props.time_created, addSystemBias); | |
| 311 | } | ||
| 312 | 1 | DateTime File::Entry::getTimeModified(bool_t addSystemBias) const | |
| 313 | { | ||
| 314 | 1 | return DateTime(this->props.time_modified, addSystemBias); | |
| 315 | } | ||
| 316 | 1 | DateTime File::Entry::getTimeAccessed(bool_t addSystemBias) const | |
| 317 | { | ||
| 318 | 1 | return DateTime(this->props.time_accessed, addSystemBias); | |
| 319 | } | ||
| 320 | |||
| 321 | |||
| 322 | 2 | bool_t File::Entry::isDirectory() const | |
| 323 | { | ||
| 324 | 2 | return GATE_FLAG_ENABLED(this->props.attribs, GATE_FILEENTRY_ATTRIB_DIRECTORY); | |
| 325 | } | ||
| 326 | 2 | bool_t File::Entry::isVolume() const | |
| 327 | { | ||
| 328 | 2 | return GATE_FLAG_ENABLED(this->props.attribs, GATE_FILEENTRY_ATTRIB_VOLUME); | |
| 329 | } | ||
| 330 | 2 | bool_t File::Entry::isExecutable() const | |
| 331 | { | ||
| 332 | 2 | return 0 != (this->props.access & (GATE_FILEENTRY_ACCESS_OWNEREXECUTE | GATE_FILEENTRY_ACCESS_GROUPEXECUTE | GATE_FILEENTRY_ACCESS_ALLEXECUTE)); | |
| 333 | } | ||
| 334 | |||
| 335 | |||
| 336 | 19 | File::Properties::Properties(gate_file_properties_t const& props) | |
| 337 | { | ||
| 338 | 19 | gate_mem_copy(static_cast<gate_file_properties_t*>(this), | |
| 339 | static_cast<gate_file_properties_t const*>(&props), | ||
| 340 | sizeof(gate_file_properties_t)); | ||
| 341 | 19 | } | |
| 342 | 18 | File::Properties::Properties(Properties const& src) | |
| 343 | { | ||
| 344 | 18 | gate_mem_copy(static_cast<gate_file_properties_t*>(this), | |
| 345 | static_cast<gate_file_properties_t const*>(&src), | ||
| 346 | sizeof(gate_file_properties_t)); | ||
| 347 | |||
| 348 | 18 | } | |
| 349 | 2 | File::Properties& File::Properties::operator=(Properties const& src) | |
| 350 | { | ||
| 351 | 2 | gate_mem_copy(static_cast<gate_file_properties_t*>(this), | |
| 352 | static_cast<gate_file_properties_t const*>(&src), | ||
| 353 | sizeof(gate_file_properties_t)); | ||
| 354 | 2 | return *this; | |
| 355 | } | ||
| 356 | 37 | File::Properties::~Properties() | |
| 357 | { | ||
| 358 | |||
| 359 | 37 | } | |
| 360 | |||
| 361 | 3 | uint64_t File::Properties::getSize() const | |
| 362 | { | ||
| 363 | 3 | return this->size; | |
| 364 | } | ||
| 365 | 1 | enumint_t File::Properties::getAttributes() const | |
| 366 | { | ||
| 367 | 1 | return this->attribs; | |
| 368 | } | ||
| 369 | 1 | enumint_t File::Properties::getAccessBits() const | |
| 370 | { | ||
| 371 | 1 | return this->access; | |
| 372 | } | ||
| 373 | 1 | DateTime File::Properties::getTimeCreated(bool_t addSystemBias) const | |
| 374 | { | ||
| 375 | 1 | return DateTime(this->time_created, addSystemBias); | |
| 376 | } | ||
| 377 | 1 | DateTime File::Properties::getTimeModified(bool_t addSystemBias) const | |
| 378 | { | ||
| 379 | 1 | return DateTime(this->time_modified, addSystemBias); | |
| 380 | } | ||
| 381 | 1 | DateTime File::Properties::getTimeAccessed(bool_t addSystemBias) const | |
| 382 | { | ||
| 383 | 1 | return DateTime(this->time_accessed, addSystemBias); | |
| 384 | } | ||
| 385 | |||
| 386 | 1 | bool_t File::Properties::isDirectory() const | |
| 387 | { | ||
| 388 | 1 | return GATE_FLAG_ENABLED(this->attribs, GATE_FILEENTRY_ATTRIB_DIRECTORY); | |
| 389 | } | ||
| 390 | 1 | bool_t File::Properties::isVolume() const | |
| 391 | { | ||
| 392 | 1 | return GATE_FLAG_ENABLED(this->attribs, GATE_FILEENTRY_ATTRIB_VOLUME); | |
| 393 | } | ||
| 394 | 1 | bool_t File::Properties::isExecutable() const | |
| 395 | { | ||
| 396 | 1 | return 0 != (this->access & | |
| 397 | 1 | (GATE_FILEENTRY_ACCESS_ALLEXECUTE | GATE_FILEENTRY_ACCESS_GROUPEXECUTE | GATE_FILEENTRY_ACCESS_OWNEREXECUTE)); | |
| 398 | } | ||
| 399 | |||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | |||
| 404 | 2 | static bool_t GATE_CALL gate_file_list_entries(gate_file_entry_t const* ptr, void* userparam) | |
| 405 | { | ||
| 406 | 2 | gate_directory_list_entries_struct* param = (gate_directory_list_entries_struct*)userparam; | |
| 407 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | File::Entry entry(*ptr); |
| 408 | 2 | bool_t continue_listing = true; | |
| 409 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | param->delegate_cb(&entry, param->user_param, &continue_listing); |
| 410 | 4 | return continue_listing; | |
| 411 | } | ||
| 412 | |||
| 413 | 1 | void File::listEntries(String const& dirpath, callback_t const& callback, void* userparam) | |
| 414 | { | ||
| 415 | 2 | gate_directory_list_entries_struct param(callback, userparam); | |
| 416 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | gate_result_t result = gate_file_list(dirpath.c_impl(), &gate_file_list_entries, ¶m); |
| 417 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 418 | 1 | } | |
| 419 | 2 | static bool_t GATE_CALL gate_file_list_entries_in_map(gate_file_entry_t const* ptr, void* userparam) | |
| 420 | { | ||
| 421 | 2 | File::pathmap_t* mapping = static_cast<File::pathmap_t*>(userparam); | |
| 422 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | String path(ptr->path); |
| 423 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | String name(ptr->name); |
| 424 | 2 | mapping->tryAdd(path, name); | |
| 425 | 4 | return true; | |
| 426 | } | ||
| 427 | |||
| 428 | 1 | File::pathmap_t File::listEntryPaths(String const& dirpath) | |
| 429 | { | ||
| 430 | 1 | File::pathmap_t paths; | |
| 431 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_list(dirpath.c_impl(), &gate_file_list_entries_in_map, &paths); |
| 432 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 433 | 1 | return paths; | |
| 434 | } | ||
| 435 | |||
| 436 | 1 | void File::listRootEntries(callback_t const& callback, void* userparam) | |
| 437 | { | ||
| 438 | 2 | gate_directory_list_entries_struct param(callback, userparam); | |
| 439 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_result_t result = gate_file_root_list(&gate_file_list_entries, ¶m); |
| 440 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 441 | 1 | } | |
| 442 | |||
| 443 | |||
| 444 | 1 | File::pathmap_t File::listRootEntryPaths() | |
| 445 | { | ||
| 446 | 1 | File::pathmap_t paths; | |
| 447 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_file_root_list(&gate_file_list_entries_in_map, &paths); |
| 448 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 449 | 1 | return paths; | |
| 450 | } | ||
| 451 | |||
| 452 | |||
| 453 | 1 | File::Entry File::getEntry(String const& filepath) | |
| 454 | { | ||
| 455 | gate_file_entry_t direntry; | ||
| 456 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | gate_result_t res = gate_file_get_entry(filepath.c_impl(), &direntry); |
| 457 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 458 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return File::Entry(direntry); |
| 459 | } | ||
| 460 | 3 | void File::createDirectory(String const& dirpath, CreateDirEnum mode) | |
| 461 | { | ||
| 462 | 3 | result_t res = gate_file_dir_create(dirpath.c_impl(), static_cast<gate_enumint_t>(mode)); | |
| 463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_EXCEPTION(res); |
| 464 | 3 | } | |
| 465 | 1 | void File::createAllDirectories(String const& dirpath, CreateDirEnum mode) | |
| 466 | { | ||
| 467 | 1 | result_t res = gate_file_dir_create_all(dirpath.c_impl(), static_cast<gate_enumint_t>(mode)); | |
| 468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 469 | 1 | } | |
| 470 | |||
| 471 | 1 | void File::removeDirectory(String const& dirpath) | |
| 472 | { | ||
| 473 | 1 | result_t res = gate_file_dir_delete(dirpath.c_impl()); | |
| 474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 475 | 1 | } | |
| 476 | 2 | void File::removeDirectoryRecursive(String const& dirpath) | |
| 477 | { | ||
| 478 | 2 | result_t res = gate_file_dir_delete_recursive(dirpath.c_impl()); | |
| 479 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(res); |
| 480 | 2 | } | |
| 481 | |||
| 482 | |||
| 483 | 2 | bool_t File::isDirectory(String const& dirpath) | |
| 484 | { | ||
| 485 | 2 | result_t res = gate_file_dir_exists(dirpath.c_impl()); | |
| 486 | 2 | return GATE_SUCCEEDED(res); | |
| 487 | } | ||
| 488 | 1 | bool_t File::isHidden(String const& path) | |
| 489 | { | ||
| 490 | 1 | bool_t ret = false; | |
| 491 | 1 | gate_enumint_t attrib = 0; | |
| 492 | 1 | gate_enumint_t accessbits = 0; | |
| 493 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_get_attributes(path.c_impl(), &attrib, &accessbits); |
| 494 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 495 | { | ||
| 496 | 1 | ret = GATE_FLAG_ENABLED(attrib, GATE_FILEENTRY_ATTRIB_HIDDEN); | |
| 497 | } | ||
| 498 | 1 | return ret; | |
| 499 | } | ||
| 500 | 1 | bool_t File::isExecutable(String const& filepath) | |
| 501 | { | ||
| 502 | 1 | bool_t ret = false; | |
| 503 | 1 | gate_enumint_t attrib = 0; | |
| 504 | 1 | gate_enumint_t accessbits = 0; | |
| 505 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_get_attributes(filepath.c_impl(), &attrib, &accessbits); |
| 506 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 507 | { | ||
| 508 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!GATE_FLAG_ENABLED(attrib, GATE_FILEENTRY_ATTRIB_DIRECTORY)) |
| 509 | { | ||
| 510 | 1 | ret = (0 != (accessbits & | |
| 511 | (GATE_FILEENTRY_ACCESS_OWNEREXECUTE | ||
| 512 | | GATE_FILEENTRY_ACCESS_GROUPEXECUTE | ||
| 513 | | GATE_FILEENTRY_ACCESS_ALLEXECUTE)) | ||
| 514 | ); | ||
| 515 | } | ||
| 516 | } | ||
| 517 | 1 | return ret; | |
| 518 | } | ||
| 519 | |||
| 520 | |||
| 521 | 2 | String File::getContent(String const& filePath) | |
| 522 | { | ||
| 523 | 2 | gate_string_t buffer = GATE_STRING_INIT_EMPTY; | |
| 524 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result_t result = gate_file_get_content(filePath.c_impl(), &buffer); |
| 525 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 526 | 4 | return String::createFrom(buffer); | |
| 527 | } | ||
| 528 | 1 | size_t File::getContent(String const& filePath, char* buffer, size_t buffer_len) | |
| 529 | { | ||
| 530 | 1 | result_t result = gate_file_get_content_buffer(filePath.c_impl(), buffer, &buffer_len); | |
| 531 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 532 | 1 | return buffer_len; | |
| 533 | } | ||
| 534 | 1 | ArrayList<String> File::getContentLines(String const& filePath) | |
| 535 | { | ||
| 536 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ArrayList<String> ret; |
| 537 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | GenericArrayList list(gate_util_stringarray_create()); |
| 538 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (!list.c_impl()) |
| 539 | { | ||
| 540 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 541 | } | ||
| 542 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | result_t result = gate_file_get_content_lines(filePath.c_impl(), list.c_impl()); |
| 543 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 544 | { | ||
| 545 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | ret = util::convertStringArray(list.c_impl()); |
| 546 | } | ||
| 547 | 2 | return ret; | |
| 548 | } | ||
| 549 | 1 | void File::setContent(String const& filePath, String const& content) | |
| 550 | { | ||
| 551 | 1 | result_t result = gate_file_set_content(filePath.c_impl(), content.c_impl()); | |
| 552 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 553 | 1 | } | |
| 554 | 1 | void File::setContent(String const& filePath, char const* buffer, size_t buffer_len) | |
| 555 | { | ||
| 556 | 1 | result_t result = gate_file_set_content_buffer(filePath.c_impl(), buffer, buffer_len); | |
| 557 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 558 | 1 | } | |
| 559 | 1 | void File::setContentLines(String const& filePath, ArrayList<String> const& lines) | |
| 560 | { | ||
| 561 | 1 | gate_arraylist_t list = util::convertStringArray(lines); | |
| 562 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!list) |
| 563 | { | ||
| 564 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 565 | } | ||
| 566 | 1 | result_t result = gate_file_set_content_lines(filePath.c_impl(), list); | |
| 567 | 1 | gate_arraylist_release(list); | |
| 568 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 569 | 1 | } | |
| 570 | |||
| 571 | 1 | File::SearchFilter::SearchFilter(String const& pattern, bool_t recursive, | |
| 572 | uint64_t fromSize, uint64_t toSize, | ||
| 573 | 1 | timestamp_t fromModified, timestamp_t toModified) | |
| 574 | { | ||
| 575 | 1 | gate_string_duplicate(&this->pattern, pattern.c_impl()); | |
| 576 | 1 | this->recursive = recursive; | |
| 577 | 1 | this->from_size = fromSize; | |
| 578 | 1 | this->to_size = toSize; | |
| 579 | 1 | this->from_modified = fromModified; | |
| 580 | 1 | this->to_modified = toModified; | |
| 581 | 1 | } | |
| 582 | 2 | File::SearchFilter::~SearchFilter() noexcept | |
| 583 | { | ||
| 584 | 1 | gate_string_release(&this->pattern); | |
| 585 | 1 | } | |
| 586 | |||
| 587 | ✗ | void File::SearchFilter::setPattern(String const& pattern) | |
| 588 | { | ||
| 589 | ✗ | String::assign(this->pattern, pattern); | |
| 590 | ✗ | } | |
| 591 | ✗ | String File::SearchFilter::getPattern() const | |
| 592 | { | ||
| 593 | ✗ | return String::clone(this->pattern); | |
| 594 | } | ||
| 595 | |||
| 596 | struct GATE_API_LOCAL File_find_dispatcher_param | ||
| 597 | { | ||
| 598 | File::callback_t const* ptr_cb; | ||
| 599 | void* user_param; | ||
| 600 | Exception user_error; | ||
| 601 | |||
| 602 | 1 | File_find_dispatcher_param() | |
| 603 | 1 | : user_error(results::Ok) | |
| 604 | { | ||
| 605 | 1 | } | |
| 606 | }; | ||
| 607 | |||
| 608 | 27 | static gate_bool_t GATE_CALL File_find_dispatcher(gate_file_entry_t const* ptr_entry, void* userparam) | |
| 609 | { | ||
| 610 | 27 | File_find_dispatcher_param* ptr_param = static_cast<File_find_dispatcher_param*>(userparam); | |
| 611 | 27 | bool_t continueSearch = true; | |
| 612 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | if (ptr_entry) |
| 613 | { | ||
| 614 |
1/2✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
|
54 | File::Entry entry(*ptr_entry); |
| 615 | #if defined(GATEXX_NO_EXCEPTIONS) | ||
| 616 | VoidResult result = ptr_param->ptr_cb->tryInvoke(&entry, ptr_param->user_param, &continueSearch); | ||
| 617 | if (result.hasError()) | ||
| 618 | { | ||
| 619 | ptr_param->user_error = Exception(result.error(), NULL, "File_find_dispatcher"); | ||
| 620 | continueSearch = false; | ||
| 621 | } | ||
| 622 | #else | ||
| 623 | try | ||
| 624 | { | ||
| 625 |
1/2✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
|
27 | ptr_param->ptr_cb->invoke(&entry, ptr_param->user_param, &continueSearch); |
| 626 | } | ||
| 627 | ✗ | catch(Throwable const& xcpt) | |
| 628 | { | ||
| 629 | ✗ | ptr_param->user_error = Exception(xcpt.getResult(), xcpt.getMessage(), xcpt.getSource(), xcpt.getErrorCode()); | |
| 630 | ✗ | continueSearch = false; | |
| 631 | } | ||
| 632 | ✗ | catch(...) | |
| 633 | { | ||
| 634 | ✗ | ptr_param->user_error = Exception(results::UnknownException, NULL, "File::find_dispatcher"); | |
| 635 | ✗ | continueSearch = false; | |
| 636 | } | ||
| 637 | #endif | ||
| 638 | } | ||
| 639 | 27 | return continueSearch; | |
| 640 | } | ||
| 641 | |||
| 642 | 1 | void File::find(String const& path, SearchFilter const& filter, callback_t const& callback, void* userparam) | |
| 643 | { | ||
| 644 | 2 | File_find_dispatcher_param param; | |
| 645 | 1 | param.ptr_cb = &callback; | |
| 646 | 1 | param.user_param = userparam; | |
| 647 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_file_find(path.c_impl(), &filter, &File_find_dispatcher, ¶m); |
| 648 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 649 | |||
| 650 | 1 | Exception const& xcpt = param.user_error; | |
| 651 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (GATE_FAILED(xcpt.getResult())) |
| 652 | { | ||
| 653 | ✗ | gate::raiseException( | |
| 654 | xcpt.getResult(), xcpt.getMessage(), | ||
| 655 | xcpt.getSource(), xcpt.getErrorCode()); | ||
| 656 | } | ||
| 657 | 1 | } | |
| 658 | |||
| 659 | |||
| 660 | |||
| 661 | char const FilePath::SeparatorChar = gate_file_path_separator_character();; | ||
| 662 | |||
| 663 | 2 | String const& FilePath::Separator() | |
| 664 | { | ||
| 665 | static char const chrs[2] = { | ||
| 666 | 2 | gate_file_path_separator_character(), | |
| 667 | 0 | ||
| 668 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
2 | } ; |
| 669 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | static StaticString const sep = StaticString(chrs, 1); |
| 670 | 2 | return sep; | |
| 671 | } | ||
| 672 | |||
| 673 | ✗ | FilePath::FilePath() | |
| 674 | { | ||
| 675 | ✗ | } | |
| 676 | 2 | FilePath::FilePath(FilePath const& src) | |
| 677 | 2 | : value(src.value) | |
| 678 | { | ||
| 679 | 2 | } | |
| 680 | 15 | FilePath::FilePath(String const& path) | |
| 681 | 15 | : value(path) | |
| 682 | { | ||
| 683 | 15 | } | |
| 684 | ✗ | FilePath& FilePath::operator=(FilePath const& src) | |
| 685 | { | ||
| 686 | ✗ | this->value = src.value; | |
| 687 | ✗ | return *this; | |
| 688 | } | ||
| 689 | 17 | FilePath::~FilePath() | |
| 690 | { | ||
| 691 | 17 | } | |
| 692 | |||
| 693 | 7 | FilePath FilePath::build(String const& parent, String const& child) | |
| 694 | { | ||
| 695 | 7 | return FilePath(File::buildPath(parent, child)); | |
| 696 | } | ||
| 697 | |||
| 698 | 1 | ArrayList<String> FilePath::split(String const& path, char pathSeparator) | |
| 699 | { | ||
| 700 | gate_string_t components[512]; | ||
| 701 | |||
| 702 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_mem_clear(&components[0], sizeof(components)); |
| 703 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (pathSeparator == 0) |
| 704 | { | ||
| 705 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pathSeparator = gate_file_path_separator_character(); |
| 706 | } | ||
| 707 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | String basePath = path.clone(); |
| 708 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | size_t used = gate_file_split_path_components(basePath.c_impl(), pathSeparator, components, sizeof(components) / sizeof(components[0])); |
| 709 | |||
| 710 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ArrayList<String> ret(used); |
| 711 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (size_t ndx = 0; ndx != used; ++ndx) |
| 712 | { | ||
| 713 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | ret.add(String::createFrom(components[ndx])); |
| 714 | } | ||
| 715 | |||
| 716 | 2 | return ret; | |
| 717 | } | ||
| 718 | |||
| 719 | 1 | ArrayList<String> FilePath::split(String const& path) | |
| 720 | { | ||
| 721 | static char const defaultPathSeparator = 0; | ||
| 722 | 1 | return FilePath::split(path, defaultPathSeparator); | |
| 723 | } | ||
| 724 | |||
| 725 | |||
| 726 | |||
| 727 | 1 | FilePath FilePath::getParent() const | |
| 728 | { | ||
| 729 | 2 | String parent; | |
| 730 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | if (File::getParent(this->value, parent)) |
| 731 | { | ||
| 732 | 1 | return FilePath(parent); | |
| 733 | } | ||
| 734 | else | ||
| 735 | { | ||
| 736 | ✗ | return FilePath(); | |
| 737 | } | ||
| 738 | } | ||
| 739 | 1 | FilePath FilePath::getName() const | |
| 740 | { | ||
| 741 | 2 | String name; | |
| 742 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | if (File::getName(this->value, name)) |
| 743 | { | ||
| 744 | 1 | return FilePath(name); | |
| 745 | } | ||
| 746 | else | ||
| 747 | { | ||
| 748 | ✗ | return FilePath(); | |
| 749 | } | ||
| 750 | } | ||
| 751 | 14 | String FilePath::toString() const | |
| 752 | { | ||
| 753 | 14 | return this->value; | |
| 754 | } | ||
| 755 | |||
| 756 | 2 | FilePath& FilePath::append(FilePath const& path) | |
| 757 | { | ||
| 758 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | String newPath = File::buildPath(this->value, path.toString()); |
| 759 | 2 | this->value = newPath; | |
| 760 | 4 | return *this; | |
| 761 | } | ||
| 762 | |||
| 763 | 1 | FilePath& FilePath::operator/=(FilePath const& path) | |
| 764 | { | ||
| 765 | 1 | return this->append(path); | |
| 766 | } | ||
| 767 | 1 | FilePath& FilePath::operator/=(char const* path) | |
| 768 | { | ||
| 769 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | return this->append(FilePath(String::createStatic(path))); |
| 770 | } | ||
| 771 | |||
| 772 | 2 | FilePath FilePath::operator/(FilePath const& path) const | |
| 773 | { | ||
| 774 | 2 | return FilePath::build(this->value, path.value); | |
| 775 | } | ||
| 776 | 5 | FilePath FilePath::operator/(char const* path) const | |
| 777 | { | ||
| 778 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | return FilePath::build(this->value, String::createStatic(path)); |
| 779 | } | ||
| 780 | |||
| 781 | |||
| 782 | ✗ | FilePath::operator String() const | |
| 783 | { | ||
| 784 | ✗ | return this->toString(); | |
| 785 | } | ||
| 786 | |||
| 787 | |||
| 788 | 2 | FileDirReader::FileDirReader(String const& dirpath) | |
| 789 | { | ||
| 790 | 2 | result_t result = gate_file_dir_open(dirpath.c_impl(), &this->impl); | |
| 791 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 792 | 2 | } | |
| 793 | |||
| 794 | 2 | String FileDirReader::nextFilename() | |
| 795 | { | ||
| 796 | char pathBuffer[GATE_MAX_FILEPATH_LENGTH]; | ||
| 797 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t pathLength = gate_file_dir_read(&this->impl, pathBuffer, sizeof(pathBuffer), true); |
| 798 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (pathLength) |
| 799 | { | ||
| 800 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | return String(pathBuffer, pathLength); |
| 801 | } | ||
| 802 | 1 | return String(); | |
| 803 | } | ||
| 804 | 2 | String FileDirReader::nextPath() | |
| 805 | { | ||
| 806 | char pathBuffer[GATE_MAX_FILEPATH_LENGTH]; | ||
| 807 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t pathLength = gate_file_dir_read(&this->impl, pathBuffer, sizeof(pathBuffer), false); |
| 808 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (pathLength) |
| 809 | { | ||
| 810 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | return String(pathBuffer, pathLength); |
| 811 | } | ||
| 812 | 1 | return String(); | |
| 813 | } | ||
| 814 | |||
| 815 | 4 | FileDirReader::~FileDirReader() | |
| 816 | { | ||
| 817 | 2 | gate_file_dir_close(&this->impl); | |
| 818 | 2 | } | |
| 819 | |||
| 820 | |||
| 821 | |||
| 822 | } // end of namespace gate | ||
| 823 |