From 5c7c3cf23799eb4aa73df06a60303c37a65cb0d7 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 21 Apr 2021 14:44:49 +0200 Subject: [PATCH] Program skeleton --- checks.go | 27 +++++++++++++++++++++++ commit.go | 26 ++++++++++++++++++++++ config.go | 7 ++++++ seafile_recovery.go | 53 +++++++-------------------------------------- 4 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 checks.go create mode 100644 commit.go create mode 100644 config.go diff --git a/checks.go b/checks.go new file mode 100644 index 0000000..a978567 --- /dev/null +++ b/checks.go @@ -0,0 +1,27 @@ +package main + +import( + "log" + "io/ioutil" + "os" + "path/filepath" +) + +func checkRootFolder(storage string) { + files, err := ioutil.ReadDir(storage) + if err != nil { log.Fatal(err) } + + checked_folders := map[string]bool{"fs": false, "commits": false, "blocks": false} + for _, f := range files { + if _, ok := checked_folders[f.Name()]; ok { + info, err := os.Stat(filepath.Join(storage, f.Name())); + if err == nil && info.IsDir() { + checked_folders[f.Name()] = true + } + } + } + + for path, seen := range checked_folders { + if !seen { log.Fatal("Folder ", path, " is required but not present!") } + } +} diff --git a/commit.go b/commit.go new file mode 100644 index 0000000..6eb4754 --- /dev/null +++ b/commit.go @@ -0,0 +1,26 @@ +package main + +import ( + "log" +) + +type Commit struct { + CommitId string `json:"commit_id"` + RootId string `json:"root_id"` + RepoId string `json:"repo_id"` + CreatorName string `json:"creator_name"` + Creator string `json:"creator"` + Description string `json:"description"` + Ctime uint64 `json:"ctime"` + ParentId string `json:"parent_id"` + SecondParentId string `json:"second_parent_id"` + RepoName string `json:"repo_name"` + RepoDesc string `json:"repo_desc"` + RepoCategory string `json:"repo_category"` + NoLocalHistory int `json:"no_local_history"` + Version int `json:"version"` +} + +func cmdCommit(config configCollect) { + log.Println(config) +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..cae70a0 --- /dev/null +++ b/config.go @@ -0,0 +1,7 @@ +package main + +type configCollect struct { + Commits bool `docopt:"commits"` + Storage string `docopt:"--storage"` + RepoId string `docopt:""` +} diff --git a/seafile_recovery.go b/seafile_recovery.go index 9cd55be..d0597a5 100644 --- a/seafile_recovery.go +++ b/seafile_recovery.go @@ -1,49 +1,10 @@ package main import ( - "io/ioutil" - "os" - "path/filepath" "log" "github.com/docopt/docopt-go" ) -type Commit struct { - CommitId string `json:"commit_id"` - RootId string `json:"root_id"` - RepoId string `json:"repo_id"` - CreatorName string `json:"creator_name"` - Creator string `json:"creator"` - Description string `json:"description"` - Ctime uint64 `json:"ctime"` - ParentId string `json:"parent_id"` - SecondParentId string `json:"second_parent_id"` - RepoName string `json:"repo_name"` - RepoDesc string `json:"repo_desc"` - RepoCategory string `json:"repo_category"` - NoLocalHistory int `json:"no_local_history"` - Version int `json:"version"` -} - -func checkFolder(storage string) { - files, err := ioutil.ReadDir(storage) - if err != nil { log.Fatal(err) } - - checked_folders := map[string]bool{"fs": false, "commits": false, "blocks": false} - for _, f := range files { - if _, ok := checked_folders[f.Name()]; ok { - info, err := os.Stat(filepath.Join(storage, f.Name())); - if err == nil && info.IsDir() { - checked_folders[f.Name()] = true - } - } - } - - for path, seen := range checked_folders { - if !seen { log.Fatal("Folder ", path, " is required but not present!") } - } -} - func main() { usage := `Seafile Recovery. @@ -55,14 +16,16 @@ Options: -h --help Show this screen --storage= Set Seafile storage path [default: ./storage]` - var config struct { - Commits bool `docopt:"commits"` - Storage string `docopt:"--storage"` - RepoId string `docopt:""` - } + var config configCollect opts, err := docopt.ParseDoc(usage) if err != nil { log.Fatal(err) } opts.Bind(&config) - checkFolder(config.Storage) + checkRootFolder(config.Storage) + + if config.Commits { + cmdCommit(config) + } else { + log.Fatal("This command is not implemented") + } }