use std::path::PathBuf;
use thiserror::Error;
use super::FileError;
use crate::directory::DestinationDirectoryRule;
#[derive(Error, Debug)]
pub enum SourceDirectoryPathValidationError {
#[error(
"source directory path does not exist: {}",
.directory_path.display()
)]
NotFound {
directory_path: PathBuf,
},
#[error(
"source path exists, but is not a directory: {}",
.path.display()
)]
NotADirectory {
path: PathBuf,
},
#[error("unable to access source directory: {}", .directory_path.display())]
UnableToAccess {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
}
#[derive(Error, Debug)]
pub enum DestinationDirectoryPathValidationError {
#[error(
"destination path exists, but is not a directory: {}",
.directory_path.display()
)]
NotADirectory {
directory_path: PathBuf,
},
#[error("unable to access destination directory: {}", .directory_path.display())]
UnableToAccess {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error(
"destination path already exists, which is against \
the configured destination directory rule ({:?}): {}",
.destination_directory_rule,
.path.display()
)]
AlreadyExists {
path: PathBuf,
destination_directory_rule: DestinationDirectoryRule,
},
#[error(
"destination directory exists and is not empty, which is against \
the configured destination directory rule ({:?}): {}",
.destination_directory_rule,
.directory_path.display(),
)]
NotEmpty {
directory_path: PathBuf,
destination_directory_rule: DestinationDirectoryRule,
},
#[error(
"destination directory path equals or points inside the source directory, \
which is invalid: {} (but source path is {})",
.destination_directory_path.display(),
.source_directory_path.display()
)]
DescendantOfSourceDirectory {
destination_directory_path: PathBuf,
source_directory_path: PathBuf,
},
}
#[derive(Error, Debug)]
pub enum DirectoryExecutionPlanError {
#[error("unable to access path: {}", .path.display())]
UnableToAccess {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error(
"a directory entry inside the source directory escaped out of it: {}",
.path.display()
)]
EntryEscapesSourceDirectory {
path: PathBuf,
},
#[error("destination directory or file already exists: {}", .path.display())]
DestinationItemAlreadyExists {
path: PathBuf,
},
#[error(
"symbolic link inside source directory is broken, \
and the behaviour is set to abort"
)]
SymbolicLinkIsBroken {
path: PathBuf,
},
}
#[derive(Error, Debug)]
#[error(
"a directory entry inside the source directory escaped out of it: {}",
.path.display()
)]
pub(crate) struct SourceSubPathNotUnderBaseSourceDirectory {
pub(crate) path: PathBuf,
}
#[derive(Error, Debug)]
pub enum CopyDirectoryPreparationError {
#[error(transparent)]
SourceDirectoryValidationError(#[from] SourceDirectoryPathValidationError),
#[error(transparent)]
DestinationDirectoryValidationError(#[from] DestinationDirectoryPathValidationError),
#[error(transparent)]
CopyPlanningError(#[from] DirectoryExecutionPlanError),
}
#[derive(Error, Debug)]
pub enum CopyDirectoryExecutionError {
#[error("unable to create directory: {}", .directory_path.display())]
UnableToCreateDirectory {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("unable to access destination path: {}", .path.display())]
UnableToAccessDestination {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error(
"an error occurred while copying a file to the destination: {}",
.file_path.display(),
)]
FileCopyError {
file_path: PathBuf,
#[source]
error: FileError,
},
#[error(
"failed while creating a symlink at {}",
.symlink_path.display()
)]
SymlinkCreationError {
symlink_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("destination directory or file has been created externally mid-execution: {}", .path.display())]
DestinationEntryUnexpected {
path: PathBuf,
},
}
#[derive(Error, Debug)]
pub enum CopyDirectoryError {
#[error(transparent)]
PreparationError(#[from] CopyDirectoryPreparationError),
#[error(transparent)]
ExecutionError(#[from] CopyDirectoryExecutionError),
}
#[derive(Error, Debug)]
pub enum MoveDirectoryPreparationError {
#[error(transparent)]
SourceDirectoryValidationError(#[from] SourceDirectoryPathValidationError),
#[error(transparent)]
DestinationDirectoryValidationError(#[from] DestinationDirectoryPathValidationError),
#[error(transparent)]
DirectoryScanError(#[from] DirectoryScanError),
#[error(transparent)]
CopyPlanningError(#[from] DirectoryExecutionPlanError),
}
#[derive(Error, Debug)]
pub enum MoveDirectoryExecutionError {
#[error("unable to access source path: {}", .path.display())]
UnableToAccessSource {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error(
"a directory entry inside the source directory escaped out of it: {}",
.path.display()
)]
EntryEscapesSourceDirectory {
path: PathBuf,
},
#[error("destination directory or file has been created externally mid-execution: {}", .path.display())]
DestinationEntryUnexpected {
path: PathBuf,
},
#[error(transparent)]
CopyDirectoryError(#[from] CopyDirectoryExecutionError),
#[error(
"only rename strategy is enabled (with no copy-and-delete \
fallback strategy), but we were unable to rename the directory"
)]
RenameFailedAndNoFallbackStrategy,
#[error("uncategorized std::io::Error")]
OtherIoError {
#[source]
error: std::io::Error,
},
}
#[derive(Error, Debug)]
pub enum MoveDirectoryError {
#[error(transparent)]
PreparationError(#[from] MoveDirectoryPreparationError),
#[error(transparent)]
ExecutionError(#[from] MoveDirectoryExecutionError),
}
#[derive(Error, Debug)]
pub enum DirectorySizeScanError {
#[error("failed while scanning directory: {}", .directory_path.display())]
ScanError {
#[source]
error: DirectoryScanError,
directory_path: PathBuf,
},
}
#[derive(Error, Debug)]
pub enum DirectoryEmptinessScanError {
#[error("path doesn't exist: {}", .path.display())]
NotFound {
path: PathBuf,
},
#[error(
"path exists, but is not a directory nor a symlink to one: {}",
.path.display()
)]
NotADirectory {
path: PathBuf,
},
#[error("unable to read directory: {}", .directory_path.display())]
UnableToReadDirectory {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("unable to read directory entry for {}", .directory_path.display())]
UnableToReadDirectoryEntry {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
}
#[derive(Error, Debug)]
pub enum DirectoryScanError {
#[error("path doesn't exist: {}", .path.display())]
NotFound {
path: PathBuf,
},
#[error(
"path exists, but is not a directory nor a symlink to one: {}",
.path.display()
)]
NotADirectory {
path: PathBuf,
},
#[error("unable to read directory: {}", .directory_path.display())]
UnableToReadDirectory {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("unable to read directory entry for {}", .directory_path.display())]
UnableToReadDirectoryEntry {
directory_path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("encountered a directory symlink cycle at {}", .directory_path.display())]
SymlinkCycleEncountered {
directory_path: PathBuf,
},
}