-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.go
76 lines (66 loc) · 1.59 KB
/
common.go
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
74
75
76
package go_bagit
import (
"fmt"
"os"
"path/filepath"
"time"
)
var (
// timeNow sets the function that returns the current time.
// This defaults to time.Now. Changes to this should only be done in tests.
timeNow = time.Now
// version is the current application version. Changes to this should only
// be done for a new release or in tests.
version = "0.3.1-alpha"
)
func GetSoftwareAgent() string {
const mod = "github.com/nyudlts/go-bagit"
//this is broken always returns "devel"
/*
info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Sprintf("go-bagit <https://%s>", mod)
}
version := "(unknown)"
for _, dep := range info.Deps {
if dep.Path == mod {
version = dep.Version
break
}
}
*/
return fmt.Sprintf("go-bagit (%s) <https://%s>", version, mod)
}
func getABS(path string) (string, error) {
abs, err := filepath.Abs(path)
if err != nil {
return abs, err
}
return abs, nil
}
func fileExists(file string) error {
if _, err := os.Stat(file); err == nil {
return nil
} else if os.IsNotExist(err) {
errorMsg := fmt.Errorf("file %s does not exist", file)
return errorMsg
} else {
log.Println("- ERROR - unknown error:", err.Error())
return err
}
}
func directoryExists(inputDir string) error {
if fi, err := os.Stat(inputDir); err == nil {
if fi.IsDir() {
return nil
} else {
errorMsg := fmt.Errorf("- ERROR - input directory %s is not a directory", inputDir)
return errorMsg
}
} else if os.IsNotExist(err) {
errorMsg := fmt.Errorf("- ERROR - input %s directory does not exist", inputDir)
return errorMsg
} else {
return err
}
}