1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Wildland Project
//
// Copyright © 2023 Golem Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as published by
// the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use thiserror::Error;

use crate::PathResolutionError;

#[derive(Debug, Error, PartialEq, Eq, Clone)]
#[repr(C)]
pub enum DfsFrontendError {
    #[error("Operation not permitted on other nodes than files")]
    NotAFile,
    #[error("Operation not permitted on other nodes than directories")]
    NotADirectory,
    #[error("Path does not exist")]
    NoSuchPath,
    #[error(transparent)]
    PathResolutionError(#[from] PathResolutionError),
    #[error("Path already exists")]
    PathAlreadyExists,
    #[error("Parent of the provided path does not exist or is a file")]
    InvalidParent,
    #[error("Storages didn't respond: {0}")]
    StorageNotResponsive(String),
    #[error("Insufficient quota for uploading {0} bytes")]
    InsufficientQuota(usize),
    #[error("Operation could not modify read-only path")]
    ReadOnlyPath,
    #[error("Directory is not empty")]
    DirNotEmpty,
    #[error("DFS Error: {0}")]
    Generic(String),
    #[error("Source path and target path are in different Containers")]
    MoveBetweenContainers,
    #[error("The new pathname contained a path prefix of the old, or, more generally, an attempt was made to make a directory a subdirectory of itself.")]
    SourceIsParentOfTarget,
    #[error("Operation aborted")]
    Aborted,
    #[error("Operation not supported")]
    NotSupported,
    #[error("Path `{0}` exists in more than one container")]
    PathConflict(String),
    #[error("Encryptor Adapter Error: {0}")]
    Encryption(String),
    #[error("Permission error: {0}")]
    PermissionError(String),
}

impl From<std::io::Error> for DfsFrontendError {
    fn from(err: std::io::Error) -> Self {
        DfsFrontendError::Generic(err.to_string())
    }
}

impl From<anyhow::Error> for DfsFrontendError {
    fn from(err: anyhow::Error) -> Self {
        DfsFrontendError::Generic(err.to_string())
    }
}