aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/iterator.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/folder/iterator.h
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/folder/iterator.h')
-rw-r--r--util/folder/iterator.h182
1 files changed, 91 insertions, 91 deletions
diff --git a/util/folder/iterator.h b/util/folder/iterator.h
index 35c6538e31..69e025b9c4 100644
--- a/util/folder/iterator.h
+++ b/util/folder/iterator.h
@@ -1,109 +1,109 @@
#pragma once
-
-#include "fts.h"
-
-#include <util/system/error.h>
-#include <util/generic/ptr.h>
-#include <util/generic/iterator.h>
-#include <util/generic/yexception.h>
-
+
+#include "fts.h"
+
+#include <util/system/error.h>
+#include <util/generic/ptr.h>
+#include <util/generic/iterator.h>
+#include <util/generic/yexception.h>
+
/// Note this magic API traverses directory hierarchy
class TDirIterator: public TInputRangeAdaptor<TDirIterator> {
- struct TFtsDestroy {
+ struct TFtsDestroy {
static inline void Destroy(FTS* f) noexcept {
- yfts_close(f);
- }
- };
-
-public:
- class TError: public TSystemError {
- public:
- inline TError(int err)
- : TSystemError(err)
- {
- }
- };
-
+ yfts_close(f);
+ }
+ };
+
+public:
+ class TError: public TSystemError {
+ public:
+ inline TError(int err)
+ : TSystemError(err)
+ {
+ }
+ };
+
using TCompare = int (*)(const FTSENT**, const FTSENT**);
-
- struct TOptions {
- inline TOptions() {
- Init(FTS_PHYSICAL);
- }
-
- inline TOptions(int opts) {
- Init(opts);
- }
-
+
+ struct TOptions {
+ inline TOptions() {
+ Init(FTS_PHYSICAL);
+ }
+
+ inline TOptions(int opts) {
+ Init(opts);
+ }
+
inline TOptions& SetMaxLevel(size_t level) noexcept {
- MaxLevel = level;
-
- return *this;
- }
-
+ MaxLevel = level;
+
+ return *this;
+ }
+
inline TOptions& SetSortFunctor(TCompare cmp) noexcept {
- Cmp = cmp;
-
- return *this;
- }
-
+ Cmp = cmp;
+
+ return *this;
+ }
+
TOptions& SetSortByName() noexcept;
-
- int FtsOptions;
- size_t MaxLevel;
- TCompare Cmp;
-
- private:
+
+ int FtsOptions;
+ size_t MaxLevel;
+ TCompare Cmp;
+
+ private:
inline void Init(int opts) noexcept {
- FtsOptions = opts | FTS_NOCHDIR;
- MaxLevel = Max<size_t>();
+ FtsOptions = opts | FTS_NOCHDIR;
+ MaxLevel = Max<size_t>();
Cmp = nullptr;
- }
- };
-
+ }
+ };
+
inline TDirIterator(const TString& path, const TOptions& options = TOptions())
- : Options_(options)
- , Path_(path)
- {
- Trees_[0] = Path_.begin();
+ : Options_(options)
+ , Path_(path)
+ {
+ Trees_[0] = Path_.begin();
Trees_[1] = nullptr;
-
- ClearLastSystemError();
- FileTree_.Reset(yfts_open(Trees_, Options_.FtsOptions, Options_.Cmp));
-
- const int err = LastSystemError();
-
- if (err) {
- ythrow TError(err) << "can not open '" << Path_ << "'";
- }
- }
-
- inline FTSENT* Next() {
- FTSENT* ret = yfts_read(FileTree_.Get());
-
- if (ret) {
- if ((size_t)(ret->fts_level + 1) > Options_.MaxLevel) {
- yfts_set(FileTree_.Get(), ret, FTS_SKIP);
- }
- } else {
- const int err = LastSystemError();
-
- if (err) {
- ythrow TError(err) << "error while iterating " << Path_;
- }
- }
-
- return ret;
- }
-
+
+ ClearLastSystemError();
+ FileTree_.Reset(yfts_open(Trees_, Options_.FtsOptions, Options_.Cmp));
+
+ const int err = LastSystemError();
+
+ if (err) {
+ ythrow TError(err) << "can not open '" << Path_ << "'";
+ }
+ }
+
+ inline FTSENT* Next() {
+ FTSENT* ret = yfts_read(FileTree_.Get());
+
+ if (ret) {
+ if ((size_t)(ret->fts_level + 1) > Options_.MaxLevel) {
+ yfts_set(FileTree_.Get(), ret, FTS_SKIP);
+ }
+ } else {
+ const int err = LastSystemError();
+
+ if (err) {
+ ythrow TError(err) << "error while iterating " << Path_;
+ }
+ }
+
+ return ret;
+ }
+
inline void Skip(FTSENT* ent) {
yfts_set(FileTree_.Get(), ent, FTS_SKIP);
}
-private:
- TOptions Options_;
+private:
+ TOptions Options_;
TString Path_;
- char* Trees_[2];
- THolder<FTS, TFtsDestroy> FileTree_;
-};
+ char* Trees_[2];
+ THolder<FTS, TFtsDestroy> FileTree_;
+};