Skip to content

Commit 81d9e8d

Browse files
committed
fix build 2
1 parent 061e7db commit 81d9e8d

File tree

10 files changed

+69
-62
lines changed

10 files changed

+69
-62
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{
5555
"label": "format",
5656
"type": "shell",
57-
"command": "make apply-format",
57+
"command": "make format",
5858
"problemMatcher": [],
5959
"group": "build"
6060
}

src/fsif/file.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ class file
443443
public:
444444
/**
445445
* @brief Create directory.
446-
* If this file instance is a directory then try to create that directory on the
447-
* file system. Not all file systems are writable, so not all of them support
448-
* directory creation.
449-
* The function will create all intermediate directories of the path if needed.
450-
* If the directory already exists then nothing is done.
446+
* If this file instance is a directory then try to create that directory on
447+
* the file system. Not all file systems are writable, so not all of them
448+
* support directory creation. The function will create all intermediate
449+
* directories of the path if needed. If the directory already exists then
450+
* nothing is done.
451451
* @throw std::logic_error - if file is opened.
452452
*/
453453
virtual void make_dir();
@@ -489,7 +489,8 @@ class file
489489
virtual utki::unique_ref<file> spawn() = 0;
490490

491491
// NOTE: it must not be possible to modify the const file by spawning non-const file
492-
// object and setting the same path to it, so make const spawn() overloads
492+
// object and setting the same path to it, so make const spawn()
493+
// overloads
493494
utki::unique_ref<const file> spawn() const
494495
{
495496
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
@@ -514,27 +515,23 @@ class file
514515
/**
515516
* @brief file guard class.
516517
* Use this class to open the file within the particular scope.
517-
* As the file guard object goes out of the scope it will close the file in
518-
*its destructor. Usage:
518+
* As the file guard object goes out of the scope it will close the file in its destructor.
519+
* Usage:
519520
* @code
520-
* file& fi; // assume we have some fsif::file object visible in current
521-
*scope.
521+
* file& fi; // assume we have some fsif::file object visible in current scope.
522522
* ...
523523
* {
524524
* // assume the 'fi' is closed.
525-
* // Let's create the file guard object. This will open the file
526-
*'fi'
527-
* // for reading by calling fi.open(fsif::file::mode::read)
528-
*method. fsif::file::guard file_guard(fi, fsif::file::mode::read);
525+
* // Let's create the file guard object. This will open the file 'fi'
526+
* // for reading by calling fi.open(fsif::file::mode::read) method.
527+
* fsif::file::guard file_guard(fi, fsif::file::mode::read);
529528
*
530529
* ...
531530
* // do some reading
532531
* fi.read(...);
533532
*
534-
* // going out of scope will destroy the 'file_guard' object. In
535-
*turn,
536-
* // it will automatically close the file 'fi' in its destructor
537-
*by
533+
* // going out of scope will destroy the 'file_guard' object. In turn,
534+
* // it will automatically close the file 'fi' in its destructor by
538535
* // calling fi.close() method.
539536
* }
540537
* @endcode

src/fsif/native_file.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ SOFTWARE.
4545
#include <sstream>
4646
#include <vector>
4747

48-
// On iOS < 13.0 we use 'dirent' instead of std::filesystem, since std::filesystem
49-
// becomes available only from iOS 13.0.
48+
// On iOS < 13.0 we use 'dirent' instead of std::filesystem, since
49+
// std::filesystem becomes available only from iOS 13.0.
5050
#if CFG_OS_NAME != CFG_OS_NAME_IOS || CFG_OS_IOS_DEPLOYMENT_TARGET >= 130000
5151
# include <filesystem>
5252
#endif
@@ -128,8 +128,7 @@ size_t native_file::seek_backward_internal(size_t num_bytes_to_seek) const
128128
{
129129
ASSERT(this->handle)
130130

131-
// NOTE: fseek() accepts 'long int' as offset argument which is signed and can
132-
// be
131+
// NOTE: fseek() accepts 'long int' as offset argument which is signed and can be
133132
// less than size_t value passed as argument to this function.
134133
// Therefore, do several seek operations with smaller offset if
135134
// necessary.
@@ -230,8 +229,8 @@ void native_file::make_dir()
230229
throw std::invalid_argument("invalid directory name, should end with '/'");
231230
}
232231

233-
// On iOS the std::filesystem is available only starting from iOS 13.0, so for iOS < 13.0 we do not support directory
234-
// creation.
232+
// On iOS the std::filesystem is available only starting from iOS 13.0, so for
233+
// iOS < 13.0 we do not support directory creation.
235234
#if (CFG_OS == CFG_OS_LINUX || CFG_OS == CFG_OS_MACOSX || CFG_OS == CFG_OS_WINDOWS) && \
236235
(CFG_OS_NAME != CFG_OS_NAME_IOS || CFG_OS_IOS_DEPLOYMENT_TARGET >= 130000)
237236
std::filesystem::create_directories(this->path());
@@ -295,9 +294,9 @@ std::vector<std::string> native_file::list_dir(size_t max_size) const
295294
std::vector<std::string> files;
296295

297296
// For all systems except iOS < 13.0 we use new implementation via std::filesystem.
298-
// On iOS the std::filesystem is available only starting from iOS 13.0 while it
299-
// is still desired to support iOS 11.0 at least, so for iOS < 13.0 we fall back to old
300-
// implementation via 'dirent.h'.
297+
// On iOS the std::filesystem is available only starting from iOS 13.0,
298+
// while it is still desired to support iOS 11.0 at least, so for iOS < 13.0
299+
// we fall back to old implementation via 'dirent.h'.
301300
#if CFG_OS_NAME != CFG_OS_NAME_IOS || CFG_OS_IOS_DEPLOYMENT_TARGET >= 130000
302301
std::filesystem::directory_iterator iter(this->path());
303302

@@ -400,8 +399,10 @@ std::vector<std::string> native_file::list_dir(size_t max_size) const
400399
errno = 0;
401400
while (dirent* pent = readdir(pdir)) {
402401
std::string s(pent->d_name);
403-
if (s == "." || s == "..")
404-
continue; // do not add ./ and ../ directories, we are not interested in them
402+
if (s == "." || s == "..") {
403+
// do not add ./ and ../ directories, we are not interested in them
404+
continue;
405+
}
405406

406407
struct stat fileStats;
407408
if (stat((this->path() + s).c_str(), &fileStats) < 0) {
@@ -410,8 +411,10 @@ std::vector<std::string> native_file::list_dir(size_t max_size) const
410411
throw std::system_error(errno, std::system_category(), ss.str());
411412
}
412413

413-
if (fileStats.st_mode & S_IFDIR) // if this entry is a directory append '/' symbol to its end
414+
if (fileStats.st_mode & S_IFDIR) {
415+
// if this entry is a directory append '/' symbol to its end
414416
s += "/";
417+
}
415418

416419
files.push_back(s);
417420

src/fsif/native_file.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class native_file : public file
5858

5959
size_t write_internal(utki::span<const uint8_t> buf) override;
6060

61-
// NOTE: use default implementation of seek_forward() because of the problems
62-
// with
61+
// NOTE: use default implementation of seek_forward() because of the problems with
6362
// fseek(), as it can set file pointer beyond the end of file.
6463

6564
size_t seek_backward_internal(size_t num_bytes_to_seek) const override;

src/fsif/root_dir.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace fsif {
3737
// TODO: doxygen
3838
class root_dir : public file
3939
{
40-
union base_file_union{
40+
union base_file_union {
4141
utki::unique_ref<file> variable;
4242
utki::unique_ref<const file> constant;
4343

@@ -55,29 +55,35 @@ class root_dir : public file
5555
base_file_union(base_file_union&&) = delete;
5656
base_file_union& operator=(base_file_union&&) = delete;
5757

58-
~base_file_union(){
59-
// doesn't matter on which memeber to call the destrcutor, as the difference is only in constness
58+
~base_file_union()
59+
{
60+
// doesn't matter on which memeber to call the destrcutor, as the
61+
// difference is only in constness
6062
this->variable.~unique_ref();
6163
}
6264
} base_file;
6365

6466
std::string root_directory;
6567

66-
// This constructor is private because the object it constructs can only be used in const context.
68+
// This constructor is private because the object it constructs can only be
69+
// used in const context.
6770
root_dir(
6871
utki::unique_ref<const file> base_file, //
69-
std::string root_directory
72+
std::string root_directory,
73+
bool // dummy parameter to disambiguate from the another constructor
7074
) :
7175
base_file(std::move(base_file)),
7276
root_directory(std::move(root_directory))
7377
{
7478
this->init();
7579
}
7680

77-
void init(){
81+
void init()
82+
{
7883
this->file::set_path_internal(std::string(this->base_file.constant.get().path()));
7984
this->base_file.variable.get().set_path(this->root_directory + this->path());
8085
}
86+
8187
public:
8288
/**
8389
* @param base_file - a file to wrap.
@@ -101,19 +107,13 @@ class root_dir : public file
101107
* trailing '/' character.
102108
* @return constant root_dir.
103109
*/
104-
static utki::unique_ref<const root_dir> make(
105-
utki::unique_ref<const file> base_file,
106-
std::string root_directory
107-
)
108-
{
109-
return utki::unique_ref(
110-
std::unique_ptr<const root_dir>(
111-
new root_dir(
112-
std::move(base_file),
113-
std::move(root_directory)
114-
)
115-
)
116-
);
110+
static utki::unique_ref<const root_dir> make(utki::unique_ref<const file> base_file, std::string root_directory)
111+
{
112+
return utki::unique_ref(std::unique_ptr<const root_dir>(new root_dir(
113+
std::move(base_file),
114+
std::move(root_directory),
115+
false // dummy parameter to disambiguate from the another constructor
116+
)));
117117
}
118118

119119
root_dir(const root_dir&) = delete;

src/fsif/span_file.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ class span_file : public file
7676
{}
7777

7878
span_file(utki::span<const char> data) :
79-
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
80-
span_file(utki::make_span(reinterpret_cast<const uint8_t*>(data.data()), data.size()))
79+
span_file(utki::make_span(
80+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
81+
reinterpret_cast<const uint8_t*>(data.data()),
82+
data.size()
83+
))
8184
{}
8285

8386
~span_file() noexcept override = default;

src/fsif/util.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace fsif {
3333

3434
/**
3535
* @brief Check if path represents a directory.
36-
* Empty path is not considered a directory, so the function will return false for empty path.
36+
* Empty path is not considered a directory, so the function will return false
37+
* for empty path.
3738
* @param path_name - path name to check.
3839
* @return true if path name ends with forward slash character '/'.
3940
* @return false otherwise.
@@ -101,8 +102,9 @@ std::string as_dir(std::string_view path);
101102

102103
/**
103104
* @brief Convert path to a file path.
104-
* Path to a file differs from a path to a directory by that it does not have the trailing slash '/' character.
105-
* This function removes the trailing slash character from a path if it is present.
105+
* Path to a file differs from a path to a directory by that it does not have
106+
* the trailing slash '/' character. This function removes the trailing slash
107+
* character from a path if it is present.
106108
* @param path - path to convert to a file path.
107109
* @return A path to a file.
108110
*/

src/fsif/vector_file.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class vector_file : public file
5050

5151
private:
5252
std::vector<uint8_t> data;
53-
mutable size_t idx = 0; // current file position
53+
54+
// current file position
55+
mutable size_t idx = 0;
5456

5557
public:
5658
/**

tests/span_file/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "../../src/fsif/span_file.hpp"
22

3+
#include <utki/debug.hpp>
4+
35
// NOLINTNEXTLINE(bugprone-exception-escape, "we want uncaught exceptions to fail the tests")
46
int main(int /* argc */, const char** /* argv */){
57
// test read only span_file
@@ -56,9 +58,8 @@ int main(int /* argc */, const char** /* argv */){
5658
}
5759

5860
auto file2 = file.spawn();
59-
utki::assert(file2, SL);
6061

61-
auto res = file2->load();
62+
auto res = file2.get().load();
6263

6364
file.close();
6465

tests/zip_file/tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace test_fsif_zip_file{
88
void run(){
99
// list directory contents
1010
{
11-
fsif::zip_file zip_f(std::make_unique<fsif::native_file>("test.zip"));
11+
fsif::zip_file zip_f(utki::make_unique<fsif::native_file>("test.zip"));
1212
utki::assert(!zip_f.is_dir(), SL);
1313
utki::assert(!zip_f.is_open(), SL);
1414

@@ -51,7 +51,7 @@ void run(){
5151

5252
// reading file
5353
{
54-
fsif::zip_file zip_f(std::make_unique<fsif::native_file>("test.zip"), "dir1/test2.txt");
54+
fsif::zip_file zip_f(utki::make_unique<fsif::native_file>("test.zip"), "dir1/test2.txt");
5555
utki::assert(!zip_f.is_dir(), SL);
5656
utki::assert(!zip_f.is_open(), SL);
5757

0 commit comments

Comments
 (0)