Directory tree. More...
#include <dirtree.hpp>
Public Member Functions | |
dirtree_t (dirspec_t *ds) | |
bool | is_orderable () const |
Is dirtree orderable? More... | |
dterr_t | chdir (const char *path) |
Change current directory. More... | |
qstring | getcwd () const |
Get current directory. More... | |
qstring | get_abspath (const dirtree_cursor_t &cursor, uint32 name_flags=DTN_FULL_NAME) const |
Get absolute path pointed by the cursor. More... | |
qstring | get_abspath (const char *relpath) const |
Construct an absolute path from the specified relative path. More... | |
direntry_t | resolve_cursor (const dirtree_cursor_t &cursor) const |
Resolve cursor. More... | |
direntry_t | resolve_path (const char *path) const |
Resolve path. More... | |
bool | isdir (const char *path) const |
Is a directory? More... | |
bool | isfile (const char *path) const |
Is a file? More... | |
qstring | get_entry_name (const direntry_t &de, uint32 name_flags=DTN_FULL_NAME) const |
Get entry name. More... | |
bool | is_dir_ordered (diridx_t diridx) const |
Is dir ordered? More... | |
bool | set_natural_order (diridx_t diridx, bool enable) const |
Enable/disable natural inode order in a directory. More... | |
ssize_t | get_dir_size (diridx_t diridx) const |
Get dir size. More... | |
qstring | get_entry_attrs (const direntry_t &de) const |
Get entry attributes. More... | |
bool | findfirst (dirtree_iterator_t *ff, const char *pattern) const |
Start iterating over files in a directory. More... | |
bool | findnext (dirtree_iterator_t *ff) const |
Continue iterating over files in a directory. More... | |
dterr_t | mkdir (const char *path) |
Create a directory. More... | |
dterr_t | rmdir (const char *path) |
Remove a directory. More... | |
dterr_t | link (const char *path) |
Add a file item into a directory. More... | |
dterr_t | unlink (const char *path) |
Remove a file item from a directory. More... | |
dterr_t | link (inode_t inode) |
Add an inode into the current directory. More... | |
dterr_t | unlink (inode_t inode) |
Remove an inode from the current directory. More... | |
dterr_t | rename (const char *from, const char *to) |
Rename a directory entry. More... | |
ssize_t | get_rank (diridx_t diridx, const direntry_t &de) const |
Get ordering rank of an item. More... | |
dterr_t | change_rank (const char *path, ssize_t rank_delta) |
Change ordering rank of an item. More... | |
dirtree_cursor_t | get_parent_cursor (const dirtree_cursor_t &cursor) const |
Get parent cursor. More... | |
bool | load () |
Load the tree structure from the netnode. More... | |
bool | save () const |
Save the tree structure to the netnode. More... | |
const char * | get_id () const |
netnode name | |
void | set_id (const char *nm) |
void | notify_dirtree (bool added, inode_t inode) |
Notify dirtree about a change of an inode. More... | |
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, iteration will stop, and that value returned. More... | |
dirtree_cursor_t | find_entry (const direntry_t &de) const |
Find the cursor corresponding to an entry of a directory. More... | |
Static Public Member Functions | |
static const char * | errstr (dterr_t err) |
Get textual representation of the error code. | |
static bool | isdir (const direntry_t &de) |
static bool | isfile (const direntry_t &de) |
Detailed Description
Directory tree.
This class organizes a virtual directory tree over items that are represented by dirspec_t.
Member Function Documentation
◆ is_orderable()
|
inline |
Is dirtree orderable?
- Returns
- true if the dirtree is orderable
◆ chdir()
|
inline |
◆ getcwd()
|
inline |
Get current directory.
- Returns
- the current working directory
◆ get_abspath() [1/2]
|
inline |
Get absolute path pointed by the cursor.
- Parameters
-
cursor name_flags how exactly the name should be retrieved. combination of bits for get_...name() methods bits
- Returns
- path; empty string if error
- Note
- see also resolve_cursor()
◆ get_abspath() [2/2]
|
inline |
Construct an absolute path from the specified relative path.
This function verifies the directory part of the specified path. The last component of the specified path is not verified.
- Parameters
-
relpath relative path
- Returns
- path. empty path means wrong directory part of RELPATH
◆ resolve_cursor()
|
inline |
Resolve cursor.
- Parameters
-
cursor to analyze
- Returns
- directory entry; if the cursor is bad, the resolved entry will be invalid.
- Note
- see also get_abspath()
◆ resolve_path()
|
inline |
Resolve path.
- Parameters
-
path to analyze
- Returns
- directory entry
◆ isdir()
|
inline |
Is a directory?
- Parameters
-
path to analyze
- Returns
- true if the specified path is a directory
◆ isfile()
|
inline |
Is a file?
- Parameters
-
path to analyze
- Returns
- true if the specified path is a file
◆ get_entry_name()
|
inline |
Get entry name.
- Parameters
-
de directory entry name_flags how exactly the name should be retrieved. combination of bits for get_...name() methods bits
- Returns
- name
◆ is_dir_ordered()
|
inline |
Is dir ordered?
- Returns
- true if the dirtree has natural ordering
◆ set_natural_order()
|
inline |
Enable/disable natural inode order in a directory.
- Parameters
-
diridx directory index enable action to do TRUE - enable ordering: re-order existing entries so that all subdirs are at the to beginning of the list, file entries are sorted and placed after the subdirs FALSE - disable ordering, no changes to existing entries
- Returns
- SUCCESS
◆ get_dir_size()
Get dir size.
- Parameters
-
diridx directory index
- Returns
- number of entries under this directory; if error, return -1
◆ get_entry_attrs()
|
inline |
Get entry attributes.
- Parameters
-
de directory entry
- Returns
- name
◆ findfirst()
|
inline |
Start iterating over files in a directory.
- Parameters
-
ff directory iterator. it will be initialized by the function pattern pattern to search for
- Returns
- success
◆ findnext()
|
inline |
Continue iterating over files in a directory.
- Parameters
-
ff directory iterator
- Returns
- success
◆ mkdir()
|
inline |
◆ rmdir()
|
inline |
◆ link() [1/2]
|
inline |
Add a file item into a directory.
- Parameters
-
path path to item to add to a directory
- Returns
- dterr_t error code
◆ unlink() [1/2]
|
inline |
Remove a file item from a directory.
- Parameters
-
path path to item remove from a directory
- Returns
- dterr_t error code
◆ link() [2/2]
◆ unlink() [2/2]
◆ rename()
|
inline |
Rename a directory entry.
- Parameters
-
from source path to destination path
- Returns
- dterr_t error code
- Note
- This function can also rename the item
◆ get_rank()
|
inline |
Get ordering rank of an item.
- Parameters
-
diridx index of the parent directory de directory entry
- Returns
- number in a range of [0..n) where n is the number of entries in the parent directory. -1 if error
◆ change_rank()
Change ordering rank of an item.
- Parameters
-
path path to the item rank_delta the amount of the change. positive numbers mean to move down in the list; negative numbers mean to move up.
- Returns
- dterr_t error code
- Note
- this function may disable natural ordering of the parent folder
- See also
- set_natural_order()
◆ get_parent_cursor()
|
inline |
Get parent cursor.
- Parameters
-
cursor a valid ditree cursor
- Returns
- cursor's parent
◆ load()
|
inline |
Load the tree structure from the netnode.
If dirspec_t::id is empty, the operation will be considered a success. In addition, calling load() more than once will not do anything, and will be considered a success.
- Returns
- success
- See also
- dirspec_t::id.
◆ save()
|
inline |
Save the tree structure to the netnode.
- Returns
- success
- See also
- dirspec_t::id.
◆ notify_dirtree()
|
inline |
Notify dirtree about a change of an inode.
- Parameters
-
added are we adding or deleting an inode? inode inode in question
◆ traverse()
|
inline |
Traverse dirtree, and be notified at each entry If the the visitor returns anything other than 0, iteration will stop, and that value returned.
The tree is traversed using a depth-first algorithm. It is forbidden to modify the dirtree_t during traversal; doing so will result in undefined behavior.
- Parameters
-
v the callback
- Returns
- 0, or whatever the visitor returned
◆ find_entry()
|
inline |
Find the cursor corresponding to an entry of a directory.
- Parameters
-
de directory entry
- Returns
- cursor corresponding to the directory entry
The documentation for this class was generated from the following file:
Generated by 1.9.3