pub struct Group<T> where
    T: Operate
{
Show 14 fields pub global: Rc<GlobalConfig>, pub context: Rc<ContextConfig>, pub name: GroupName, pub scope: DTScope, pub base: T, pub sources: Vec<T>, pub target: PathBuf, pub ignored: Option<RenamingRules>, pub hostname_sep: Option<HostnameSeparator>, pub allow_overwrite: Option<AllowOverwrite>, pub ignore_failure: Option<IgnoreFailure>, pub method: Option<SyncMethod>, pub subgroup_prefix: Option<SubgroupPrefix>, pub rename: RenamingRules,
}
Expand description

Configures how items are grouped.

Fields

global: Rc<GlobalConfig>

The global config object loaded from DT’s config file. This field does not appear in the config file, but is only used by DT internally. Skipping deserializing is achieved via serde’s skip_deserializing attribute, which fills a default value when deserializing.

context: Rc<ContextConfig>

The context config object loaded from config file. Like Group::global, this field does not appear in the config, but is only used by DT internally.

name: GroupName

Name of this group, used as namespace in staging root directory.

scope: DTScope

The priority of this group, used to resolve possibly duplicated items. See DTScope for details.

base: T

The base directory of all source items. This simplifies configuration files with common prefixes in the sources array.

Example

For a directory structure like:

dt/
├── dt-core/
│  └── src/
│     └── config.rs
├── dt-cli/
│  └── src/
│     └── main.rs
└── README.md

Consider the following config file:

[[local]]
base = "dt/dt-cli"
sources = ["*"]
target = "."

It will only sync src/main.rs to the configured target directory (in this case, the directory where DT is being executed).

sources: Vec<T>

Paths (relative to base) to the items to be synced.

target: PathBuf

The path of the parent dir of the final synced items.

Example

source = ["/source/file"]
target = "/tar/get"

will sync /source/file to /tar/get/file (creating non-existing directories along the way), while

source = ["/source/dir"]
target = "/tar/get/dir"

will sync source/dir to /tar/get/dir/dir (creating non-existing directories along the way).

ignored: Option<RenamingRules>

(Optional) Ignored names.

Example

Consider the following ignored setting:

ignored = [".git"]

With this setting, all files or directories with their basename as “.git” will be skipped.

Cannot contain slash in any of the patterns.

hostname_sep: Option<HostnameSeparator>

(Optional) Separator for per-host settings, default to @@.

An additional item with ${hostname_sep}$(hostname) appended to the original item name will be checked first, before looking for the original item. If the appended item is found, use this item instead of the configured one.

Also ignores items that are meant for other hosts by checking if the string after hostname_sep matches current machine’s hostname.

Example

When the following directory structure exists:

~/.ssh/
├── authorized_keys
├── authorized_keys@@sherlock
├── authorized_keys@@watson
├── config
├── config@sherlock
└── config@watson

On a machine with hostname set to watson, the below configuration (extraneous keys are omitted here)

[[local]]
...
hostname_sep = "@@"

base = "~/.ssh"
sources = ["config"]
target = "/tmp/sshconfig"
...

will result in the below target (/tmp/sshconfig):

/tmp/sshconfig/
└── config

Where /tmp/sshconfig/config mirrors the content of ~/.ssh/config@watson.

allow_overwrite: Option<AllowOverwrite>

(Optional) Whether to allow overwriting existing files. Dead symlinks are treated as non-existing, and are always overwritten (regardless of this option).

ignore_failure: Option<IgnoreFailure>

(Optional) Whether to treat errors omitted during syncing of this group as warnings. Note that errors occured before or after syncing are NOT affected.

method: Option<SyncMethod>

(Optional) Syncing method, overrides global.method key.

subgroup_prefix: Option<SubgroupPrefix>

A string to be prepended to a subgroup’s name when creating its staging directory with the Symlink syncing method, overrides global.subgroup_prefix key.

rename: RenamingRules

(Optional) Renaming rules, appends to global.rename.

Implementations

Gets the allow_overwrite key from a Group object, falls back to the allow_overwrite from its parent global config.

Gets the ignore_failure key from a Group object, falls back to the ignore_failure from its parent global config.

Gets the absolute path to this group’s staging directory, with the subgroup components padded with configured subgroup_prefixes.

Gets the method key from a Group object, falls back to the method from its parent global config.

Gets the subgroup_prefix key from a Group object, falls back to the subgroup_prefix from its parent global config.

Gets the hostname_sep key from a Group object, falls back to the hostname_sep from its parent global config.

Gets the list of renaming rules of this group, which is an array of (REGEX, SUBSTITUTION) tuples composed of global.rename and group.rename, used in Operate::make_target to rename the item. The returned list is a combination of the rules from global config and the group’s own rules.

Check if this group is templated by checking whether the context section contains this group’s name as a key.

Validates this local group, the following cases are denied:

  • Checks without querying the filesystem

    1. Empty group name

    2. Source item referencing parent (because items are first populated to the staging directory, and the structure under the staging directory depends on their original relative path to their base)

    3. Current group contains unimplemented ignored field

    4. Target and base are the same

    5. Base contains hostname_sep

    6. Source item is absolute (same reason as above)

    7. Source item contains bad globbing pattern

    8. Source item contains hostname_sep

  • Checks that need to query the filesystem

    1. Wrong type of existing staging path (if using the Symlink method)

    2. Path to staging root contains readonly parent directory (if using the Symlink method)

    3. Wrong type of existing target path

    4. Path to target contains readonly parent directory

    5. Base is unreadable

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.