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
use std::sync::Weak;
use std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};
use crate::data::{FilePath, GeneralHash, SaveFileEntryType};

#[derive(Debug, Serialize, Deserialize)]
pub enum AnalysisFile {
    File(FileInformation),
    Directory(DirectoryInformation),
    Symlink(SymlinkInformation),
    Other(OtherInformation),
}

impl AnalysisFile {
    pub fn parent(&self) -> &Mutex<Option<Weak<AnalysisFile>>> {
        match self {
            AnalysisFile::File(info) => &info.parent,
            AnalysisFile::Directory(info) => &info.parent,
            AnalysisFile::Symlink(info) => &info.parent,
            AnalysisFile::Other(info) => &info.parent,
        }
    }

    pub fn path(&self) -> &FilePath {
        match self {
            AnalysisFile::File(info) => &info.path,
            AnalysisFile::Directory(info) => &info.path,
            AnalysisFile::Symlink(info) => &info.path,
            AnalysisFile::Other(info) => &info.path,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FileInformation {
    pub path: FilePath,
    pub content_hash: GeneralHash,
    pub parent: Mutex<Option<Weak<AnalysisFile>>>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DirectoryInformation {
    pub path: FilePath,
    pub content_hash: GeneralHash,
    pub children: Mutex<Vec<Arc<AnalysisFile>>>,
    pub parent: Mutex<Option<Weak<AnalysisFile>>>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SymlinkInformation {
    pub path: FilePath,
    pub content_hash: GeneralHash,
    pub parent: Mutex<Option<Weak<AnalysisFile>>>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct OtherInformation {
    pub path: FilePath,
    pub parent: Mutex<Option<Weak<AnalysisFile>>>,
}


#[derive(Debug, Serialize)]
pub struct ResultEntryRef<'a, 'b, 'c> {
    pub ftype: &'a SaveFileEntryType,
    pub size: u64,
    pub hash: &'b GeneralHash,
    pub conflicting: Vec<&'c FilePath>,
}