aboutsummaryrefslogtreecommitdiff
path: root/restore_dir.go
blob: 2961b70679636fb640422165123d17ce04bc86a6 (plain)
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
package main

import (
	"code.laria.me/petrific/backup"
	"code.laria.me/petrific/fs"
	"code.laria.me/petrific/objects"
	"fmt"
)

func RestoreDir(args []string) int {
	usage := subcmdUsage("restore-dir", "directory object-id", nil)
	errout := subcmdErrout("restore-dir")

	if len(args) != 2 {
		usage()
		return 2
	}

	dir_path, err := abspath(args[0])
	if err != nil {
		errout(err)
		return 1
	}

	d, err := fs.OpenOSFile(dir_path)
	if err != nil {
		errout(err)
		return 1
	}

	if d.Type() != fs.FDir {
		errout(fmt.Errorf("%s is not a directory", dir_path))
		return 1
	}

	id, err := objects.ParseObjectId(args[1])
	if err != nil {
		errout(err)
		return 1
	}

	if err := backup.RestoreDir(objectstore, id, d); err != nil {
		errout(err)
		return 1
	}

	return 0
}