Index#

class barecat.Index(path, shard_size_limit=None, bufsize=None, readonly=True, wal=False, readonly_is_immutable=False)[source]#

Bases: contextlib.AbstractContextManager

Manages the SQLite database storing metadata about the files and directories in the Barecat archive.

Parameters:
  • path (Union[str, PathLike]) – Path to the SQLite database file (e.g., ‘archive.barecat’).

  • shard_size_limit (Union[int, str, None]) – Maximum size of a shard in bytes (int) or as a string like ‘1G’. If None, the shard size is unlimited.

  • bufsize (Optional[int]) – Buffer size for fetching rows.

  • readonly (bool) – Whether to open the index in read-only mode.

  • wal (bool)

  • readonly_is_immutable (bool)

Properties#

num_files

Number of files in the index.

num_dirs

Number of directories in the index.

total_size

Total size of all files in the index, in bytes.

shard_size_limit

The maximum allowed shard size, in bytes. Upon reaching this limit, a new shard is

num_used_shards

Number of shards where final, logically empty shards are not counted.

Instance Methods#

lookup_file(path[, normalized])

Look up a file by its path.

lookup_files(paths)

Look up multiple files by their paths.

lookup_dir(dirpath)

Look up a directory by its path.

lookup(path)

Look up a file or directory by its path.

__len__()

Number of files in the index.

__iter__()

Iterate over all file info objects in the index.

__contains__(path)

Check if a file exists in the index.

isfile(path)

Check if a file exists in the index.

isdir(path)

Check if a directory exists in the index.

exists(path)

Check if a file or directory exists in the index.

iter_all_fileinfos([order, bufsize])

Iterate over all file info objects in the index.

list_direct_fileinfos(dirpath[, order])

List the file info objects in a directory (non-recursively).

list_subdir_dirinfos(dirpath[, order])

List the subdirectory info objects contained in a directory (non-recursively).

iter_direct_fileinfos(diritem[, order, bufsize])

Iterate over the file info objects in a directory (non-recursively).

iter_subdir_dirinfos(diritem[, order, bufsize])

Iterate over the subdirectory info objects contained in a directory (non-recursively).

listdir_names(diritem[, order])

List the names of the files and subdirectories in a directory (non-recursively).

listdir_infos(diritem[, order])

List the file and directory info objects in a directory (non-recursively).

iterdir_names(diritem[, order, bufsize])

Iterate over the names of the files and subdirectories in a directory (non-recursively).

iterdir_infos(diritem[, order, bufsize])

Iterate over the file and directory info objects in a directory (non-recursively).

glob_paths(pattern[, recursive, include_hidden, ...])

Glob for paths matching a pattern.

iterglob_paths(pattern[, recursive, include_hidden, ...])

Iterate over paths matching a pattern.

iterglob_infos(pattern[, recursive, include_hidden, ...])

Iterate over file and directory info objects matching a pattern.

iterglob_infos_incl_excl(rules[, default_include, ...])

Iterate over infos matching rsync-style include/exclude rules.

walk_infos(rootitem[, bufsize])

Walk over the directory tree starting from a directory.

walk_names(rootitem[, bufsize])

Walk over the directory tree starting from a directory.

get_last_file()

Return the last file in the index, i.e., the one with the highest offset in the last

logical_shard_end(shard)

Return the logical end offset of a shard, which is the index of a byte immediately after

add(info)

Add a file or directory to the index.

add_file(finfo)

Add a file to the index.

add_files(finfos)

Add multiple files to the index.

update_file(path[, new_shard, new_offset, new_size, ...])

Update file metadata in the index.

add_dir(dinfo[, exist_ok])

Add a directory to the index.

rename(old, new[, allow_overwrite])

Rename a file or directory in the index.

rename_file(old, new[, allow_overwrite])

Rename a file in the index.

rename_dir(old, new[, allow_overwrite])

Rename a directory in the index.

remove_file(item)

Remove a file from the index.

remove_files(items)

Remove multiple files from the index.

remove_empty_dir(item)

Remove an empty directory from the index.

remove_recursively(item)

Remove a directory and all its contents recursively.

chmod(path, mode)

Change the mode of a file or directory.

chown(path, uid, gid)

Change the owner and group of a file or directory.

update_mtime(path, mtime_ns)

Update the modification time of a file or directory.

verify_integrity()

Verify the integrity of the index.

merge_from_other_barecat(source_index_path[, ...])

Adds the files and directories from another Barecat index to this one.

check_merge_conflicts(prefix)

Check for file/directory conflicts with attached sourcedb.

update_treestats()

Recompute size_tree and num_files_tree for all directories.

update_dirs()

Ensure all ancestor directories exist for both files and dirs.

no_triggers()

Context manager to temporarily disable triggers.

bulk_mode([drop_indexes, update_dirs_at_end, ...])

Context manager for bulk operations with automatic cleanup.

attached_database(path[, name, readonly])

Context manager to attach another SQLite database temporarily.

close()

Close the index.

optimize()

Optimize the index.

__exit__(exc_type, exc_val, exc_tb)

Exit the context manager.