40#define BAD_BLOB_IDX blob_idx_t(-1)
95static constexpr char DIRTREE_FOLDED_SEP =
'\x1d';
102 char from[2] = { DIRTREE_FOLDED_SEP,
'\0' };
189 if (
parent < r.parent )
return -1;
190 if (
parent > r.parent )
return 1;
191 if (
rank < r.rank )
return -1;
192 if (
rank > r.rank )
return 1;
264idaman
void ida_export delete_dirtree(dirtree_impl_t *d);
265idaman
bool ida_export load_dirtree(dirtree_impl_t *d);
266idaman
bool ida_export save_dirtree(dirtree_impl_t *d);
267idaman
void ida_export reset_dirtree(dirtree_impl_t *d);
268idaman
const char *ida_export dirtree_errstr(
dterr_t err);
269idaman
bool ida_export dirtree_is_orderable(
const dirtree_impl_t *d);
270idaman
dterr_t ida_export dirtree_chdir(dirtree_impl_t *d,
const char *path);
271idaman
void ida_export dirtree_getcwd(
qstring *out,
const dirtree_impl_t *d);
272idaman
void ida_export dirtree_resolve_path(
direntry_t *de,
const dirtree_impl_t *d,
const char *path);
274idaman
void ida_export dirtree_make_cursor(
dirtree_cursor_t *cursor,
const dirtree_impl_t *d,
const char *path);
275idaman
bool ida_export dirtree_get_entry_name(
qstring *out,
const dirtree_impl_t *d,
const direntry_t &de,
uint32 name_flags);
276idaman
void ida_export dirtree_get_entry_attrs(
qstring *out,
const dirtree_impl_t *d,
const direntry_t &de);
277idaman
bool ida_export dirtree_is_dir_ordered(
const dirtree_impl_t *d,
diridx_t diridx);
278idaman
dterr_t ida_export dirtree_set_natural_order(dirtree_impl_t *d,
diridx_t diridx,
bool enable);
279idaman
ssize_t ida_export dirtree_get_dir_size(dirtree_impl_t *d,
diridx_t diridx);
280idaman
bool ida_export dirtree_findfirst(dirtree_impl_t *d,
dirtree_iterator_t *ff,
const char *pattern);
282idaman
bool ida_export dirtree_get_abspath_by_cursor(
qstring *out,
const dirtree_impl_t *d,
const dirtree_cursor_t &cursor,
uint32 name_flags);
283idaman
bool ida_export dirtree_get_abspath_by_relpath(
qstring *out,
const dirtree_impl_t *d,
const char *relpath);
284idaman
dterr_t ida_export dirtree_mkdir(dirtree_impl_t *d,
const char *path);
285idaman
dterr_t ida_export dirtree_rmdir(dirtree_impl_t *d,
const char *path);
286idaman
dterr_t ida_export dirtree_fold_common_prefix(dirtree_impl_t *d,
const char *path,
char sep);
287idaman
dterr_t ida_export dirtree_link(dirtree_impl_t *d,
const char *path,
bool do_link);
288idaman
dterr_t ida_export dirtree_link_inode(dirtree_impl_t *d,
inode_t inode,
bool do_link);
289idaman
dterr_t ida_export dirtree_rename(dirtree_impl_t *d,
const char *from,
const char *to);
293idaman
dterr_t ida_export dirtree_change_rank(dirtree_impl_t *d,
const char *path,
ssize_t rank_delta);
295idaman
void ida_export notify_dirtree(dirtree_impl_t *d,
bool added,
inode_t inode);
296idaman
const char *ida_export dirtree_get_id(
const dirtree_impl_t *d);
297idaman
void ida_export dirtree_set_id(dirtree_impl_t *d,
const char *nm);
298idaman
const char *ida_export dirtree_get_nodename(
const dirtree_impl_t *d);
299idaman
void ida_export dirtree_set_nodename(dirtree_impl_t *d,
const char *nm);
302idaman
dirtree_t *ida_export dirtree_new_shadow_dirtree(dirtree_impl_t *d);
303idaman
void ida_export dirtree_add_event_handler(dirtree_impl_t *d,
class event_handler_t *h);
304idaman
bool ida_export dirtree_remove_event_handler(dirtree_impl_t *d,
class event_handler_t *h);
343 dirtree_getcwd(&out, d);
356 dirtree_get_abspath_by_cursor(&out, d, cursor, name_flags);
368 dirtree_get_abspath_by_relpath(&out, d, relpath);
380 dirtree_resolve_cursor(&de, d, cursor);
392 dirtree_make_cursor(&cursor, d, path);
402 dirtree_resolve_path(&de, d, path);
437 dirtree_get_entry_name(&out, d, de, name_flags);
455 return dirtree_set_natural_order(d, diridx, enable);
470 dirtree_get_entry_attrs(&out, d, de);
480 return dirtree_findfirst(d, ff, pattern);
488 return dirtree_findnext(d, ff);
504 dterr_t link(
const char *path) {
return dirtree_link(d, path,
true); }
528 return dirtree_rename(d, from, to);
539 const char *path=
nullptr,
540 char sep=DIRTREE_FOLDED_SEP)
542 return dirtree_fold_common_prefix(d, path, sep);
568 return dirtree_bulk_move(d, items, dstdir,
int(dst_rank), moved_items, errs);
579 return dirtree_bulk_remove(d, items, errs);
589 return dirtree_get_rank(d, diridx, de);
601 return dirtree_change_rank(d, path, rank_delta);
610 dirtree_get_parent_cursor(&parent, d, cursor);
622 return load_dirtree(d);
630 return save_dirtree(d);
636 return dirtree_get_id(d);
641 return dirtree_set_id(d, nm);
662 return dirtree_traverse(d, v);
671 dirtree_find_entry(&c,
this, de);
bool replace(const qchar *what, const qchar *with)
Replace all occurrences of 'what' with 'with'.
Definition pro.h:3412
Directory tree.
Definition dirtree.hpp:315
dterr_t link(inode_t inode)
Add an inode into the current directory.
Definition dirtree.hpp:514
bool isdir(const char *path) const
Is a directory?
Definition dirtree.hpp:412
dterr_t bulk_move(const dirtree_cursor_vec_t &items, const char *dstdir, ssize_t dst_rank=-1, dirtree_cursor_vec_t *moved_items=nullptr, dirtree_bulk_results_t *errs=nullptr)
Move many items to a directory.
Definition dirtree.hpp:561
bool isfile(const char *path) const
Is a file?
Definition dirtree.hpp:421
bool is_dir_ordered(diridx_t diridx) const
Is dir ordered?
Definition dirtree.hpp:443
direntry_t resolve_cursor(const dirtree_cursor_t &cursor) const
Resolve cursor.
Definition dirtree.hpp:377
const char * get_id() const
netnode name
Definition dirtree.hpp:634
dterr_t chdir(const char *path)
Change current directory.
Definition dirtree.hpp:336
dterr_t link(const char *path)
Add a file item into a directory.
Definition dirtree.hpp:504
dirtree_cursor_t make_cursor(const char *path) const
Make cursor from path.
Definition dirtree.hpp:389
~dirtree_t()
Definition dirtree.hpp:324
dterr_t bulk_remove(const dirtree_cursor_vec_t &items, dirtree_bulk_results_t *errs=nullptr)
Delete many items.
Definition dirtree.hpp:575
static bool isfile(const direntry_t &de)
Definition dirtree.hpp:407
dterr_t rename(const char *from, const char *to)
Rename a directory entry.
Definition dirtree.hpp:526
qstring get_abspath(const dirtree_cursor_t &cursor, uint32 name_flags=DTN_FULL_NAME) const
Get absolute path pointed by the cursor.
Definition dirtree.hpp:353
void set_id(const char *nm)
Definition dirtree.hpp:639
dirtree_t(dirspec_t *ds)
Definition dirtree.hpp:322
direntry_t resolve_path(const char *path) const
Resolve path.
Definition dirtree.hpp:399
dterr_t set_natural_order(diridx_t diridx, bool enable) const
Enable/disable natural inode order in a directory.
Definition dirtree.hpp:453
dterr_t change_rank(const char *path, ssize_t rank_delta)
Change ordering rank of an item.
Definition dirtree.hpp:599
friend struct dirtree_internal_t
Definition dirtree.hpp:318
ssize_t traverse(dirtree_visitor_t &v) const
Traverse dirtree, and be notified at each entry If the the visitor returns anything other than 0,...
Definition dirtree.hpp:660
dterr_t mkdir(const char *path)
Create a directory.
Definition dirtree.hpp:494
qstring get_entry_attrs(const direntry_t &de) const
Get entry attributes.
Definition dirtree.hpp:467
qstring get_entry_name(const direntry_t &de, uint32 name_flags=DTN_FULL_NAME) const
Get entry name.
Definition dirtree.hpp:432
bool is_orderable() const
Is dirtree orderable?
Definition dirtree.hpp:331
ssize_t get_rank(diridx_t diridx, const direntry_t &de) const
Get ordering rank of an item.
Definition dirtree.hpp:587
bool findfirst(dirtree_iterator_t *ff, const char *pattern) const
Start iterating over files in a directory.
Definition dirtree.hpp:478
dterr_t rmdir(const char *path)
Remove a directory.
Definition dirtree.hpp:499
dirtree_t(dirtree_impl_t *di)
Definition dirtree.hpp:323
qstring get_abspath(const char *relpath) const
Construct an absolute path from the specified relative path.
Definition dirtree.hpp:365
bool findnext(dirtree_iterator_t *ff) const
Continue iterating over files in a directory.
Definition dirtree.hpp:486
dirtree_cursor_t find_entry(const direntry_t &de) const
Find the cursor corresponding to an entry of a directory.
Definition dirtree.hpp:668
void notify_dirtree(bool added, inode_t inode)
Notify dirtree about a change of an inode.
Definition dirtree.hpp:647
dterr_t unlink(const char *path)
Remove a file item from a directory.
Definition dirtree.hpp:509
static bool isdir(const direntry_t &de)
Definition dirtree.hpp:406
ssize_t get_dir_size(diridx_t diridx) const
Get dir size.
Definition dirtree.hpp:462
bool load()
Load the tree structure from the netnode.
Definition dirtree.hpp:620
qstring getcwd() const
Get current directory.
Definition dirtree.hpp:340
static const char * errstr(dterr_t err)
Get textual representation of the error code.
Definition dirtree.hpp:327
dterr_t unlink(inode_t inode)
Remove an inode from the current directory.
Definition dirtree.hpp:519
dterr_t fold_common_prefix(const char *path=nullptr, char sep=DIRTREE_FOLDED_SEP)
Collapse single child folders into a single folder item The default separator (DIRTREE_FOLDED_SEP,...
Definition dirtree.hpp:538
dirtree_cursor_t get_parent_cursor(const dirtree_cursor_t &cursor) const
Get parent cursor.
Definition dirtree.hpp:607
bool save() const
Save the tree structure to the netnode.
Definition dirtree.hpp:628
Reimplementation of vector class from STL.
Definition pro.h:2262
dirtree_id_t
Built-in dirtree specializations:
Definition dirtree.hpp:679
@ DIRTREE_FUNCS
Definition dirtree.hpp:681
@ DIRTREE_LTYPES_BOOKMARKS
Definition dirtree.hpp:686
@ DIRTREE_IDAPLACE_BOOKMARKS
Definition dirtree.hpp:684
@ DIRTREE_SNIPPETS
IDB-backed script snippets.
Definition dirtree.hpp:687
@ DIRTREE_IMPORTS
Definition dirtree.hpp:683
@ DIRTREE_LOCAL_TYPES
Definition dirtree.hpp:680
@ DIRTREE_NAMES
Definition dirtree.hpp:682
@ DIRTREE_BPTS
Definition dirtree.hpp:685
@ DIRTREE_END
Definition dirtree.hpp:688
idaman dirtree_t *ida_export get_std_dirtree(dirtree_id_t id)
dterr_t
Directory tree: error codes.
Definition dirtree.hpp:213
@ DTE_NOT_DIRECTORY
item is not a directory
Definition dirtree.hpp:217
@ DTE_NOT_ORDERABLE
directory is not orderable
Definition dirtree.hpp:223
@ DTE_CANT_RENAME
failed to rename an item
Definition dirtree.hpp:220
@ DTE_OK
ok
Definition dirtree.hpp:214
@ DTE_MAX_DIR
maximum directory count achieved
Definition dirtree.hpp:222
@ DTE_NOT_FOUND
item not found
Definition dirtree.hpp:216
@ DTE_OWN_CHILD
moving inside subdirectory of itself
Definition dirtree.hpp:221
@ DTE_LAST
Definition dirtree.hpp:224
@ DTE_NOT_EMPTY
directory is not empty
Definition dirtree.hpp:218
@ DTE_BAD_PATH
invalid path
Definition dirtree.hpp:219
@ DTE_ALREADY_EXISTS
item already exists
Definition dirtree.hpp:215
qvector< inode_t > inodevec_t
Definition dirtree.hpp:30
qvector< direntry_t > direntry_vec_t
Definition dirtree.hpp:76
uval_t diridx_t
Directory indexes are simple numbers like 0,1,2,3... They are independent of inode numbers.
Definition dirtree.hpp:35
qvector< dirtree_bulk_result_t > dirtree_bulk_results_t
Definition dirtree.hpp:236
void dirtree_restore_prefix_sep(qstring *s)
Replace DIRTREE_FOLDED_SEP bytes by '/' in-place, for display only.
Definition dirtree.hpp:100
ea_t blob_idx_t
Blob index, used for storing/restoring dirtree_t information.
Definition dirtree.hpp:39
qvector< dirtree_cursor_t > dirtree_cursor_vec_t
Definition dirtree.hpp:197
qvector< diridx_t > dirvec_t
Definition dirtree.hpp:36
DECLARE_TYPE_AS_MOVABLE(direntry_t)
@ DTN_FULL_NAME
use long form of the entry name.
Definition dirtree.hpp:82
@ DTN_DISPLAY_NAME
use short, displayable form of the entry name.
Definition dirtree.hpp:84
uval_t uval_t
Definition kernwin.hpp:1926
unsigned int uint32
unsigned 32 bit value
Definition pro.h:352
uint64 ea_t
Definition pro.h:425
THREAD_SAFE void qswap(T &a, T &b)
Swap 2 objects of the same type using memory copies.
Definition pro.h:1728
uval_t inode_t
The inode_t type is the specialization specific inode number.
Definition pro.h:468
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:385
unsigned char uint8
unsigned 8 bit value
Definition pro.h:348
_qstring< char > qstring
regular string
Definition pro.h:3771
Directory entry: either a file or directory.
Definition dirtree.hpp:48
bool operator!=(const direntry_t &r) const
Definition dirtree.hpp:62
bool isdir
is 'idx' a diridx_t, or an inode_t
Definition dirtree.hpp:50
bool operator<(const direntry_t &r) const
Definition dirtree.hpp:66
bool operator>=(const direntry_t &r) const
Definition dirtree.hpp:72
bool valid() const
Definition dirtree.hpp:56
static const uval_t ROOTIDX
Definition dirtree.hpp:53
uval_t idx
diridx_t or inode_t
Definition dirtree.hpp:49
static const uval_t BADIDX
Definition dirtree.hpp:52
direntry_t(uval_t i=BADIDX, bool d=false)
Definition dirtree.hpp:55
bool operator==(const direntry_t &r) const
Definition dirtree.hpp:58
Directory tree specialization.
Definition dirtree.hpp:110
@ DSF_ORDERABLE
Definition dirtree.hpp:116
@ DSF_UNQ_NAMES
Definition dirtree.hpp:117
@ DSF_PRIVRANGE
Definition dirtree.hpp:115
@ DSF_INODE_EA
Definition dirtree.hpp:114
dirspec_t(const char *nm=nullptr, uint32 f=0)
Definition dirtree.hpp:124
virtual bool rename_inode(inode_t inode, const char *newname)=0
rename the entry
bool unique_names() const
Definition dirtree.hpp:159
virtual bool get_name(qstring *out, inode_t inode, uint32 name_flags=DTN_FULL_NAME)=0
get the entry name.
virtual qstring get_attrs(inode_t inode) const =0
uint32 dsf_flags
Definition dirtree.hpp:111
virtual ~dirspec_t()
Definition dirtree.hpp:126
bool is_orderable() const
Definition dirtree.hpp:158
virtual inode_t get_inode(const char *dirpath, const char *name)=0
get the entry inode in the specified directory
virtual void unlink_inode(inode_t inode)
event: unlinked an inode
Definition dirtree.hpp:156
bool has_inode_ea() const
Definition dirtree.hpp:160
qstring id
Definition dirtree.hpp:122
Definition dirtree.hpp:228
int idx
Definition dirtree.hpp:232
direntry_t entry
Definition dirtree.hpp:230
dterr_t err
Definition dirtree.hpp:231
diridx_t parent
Definition dirtree.hpp:229
Position in the directory tree.
Definition dirtree.hpp:166
dirtree_cursor_t(diridx_t _parent=direntry_t::BADIDX, size_t _rank=size_t(-1))
Definition dirtree.hpp:169
bool valid() const
Definition dirtree.hpp:171
DECLARE_COMPARISONS(dirtree_cursor_t)
Definition dirtree.hpp:187
size_t rank
the index into the parent directory
Definition dirtree.hpp:168
bool is_root_cursor() const
Definition dirtree.hpp:172
diridx_t parent
the parent directory
Definition dirtree.hpp:167
void set_root_cursor()
Definition dirtree.hpp:173
static dirtree_cursor_t root_cursor()
Definition dirtree.hpp:180
void swap(dirtree_cursor_t &r)
Definition dirtree.hpp:174
Helper class to iterate over files.
Definition dirtree.hpp:205
dirtree_cursor_t cursor
Definition dirtree.hpp:207
qstring pattern
Definition dirtree.hpp:206
Definition dirtree.hpp:200
A visitor, for use with dirtree_t::traverse.
Definition dirtree.hpp:245
virtual ssize_t visit(const dirtree_cursor_t &c, const direntry_t &de)=0
Will be called for each entry in the dirtree_t If something other than 0 is returned,...
virtual ~dirtree_visitor_t()
Definition dirtree.hpp:246