-
Notifications
You must be signed in to change notification settings - Fork 15
/
dir.go
109 lines (88 loc) · 2.69 KB
/
dir.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package sequentiallygenerateplanetmbtiles
import (
"log"
"os"
"path/filepath"
"github.com/lambdajack/sequentially-generate-planet-mbtiles/internal/system"
)
type paths struct {
workingDir string
outDir string
coastlineDir string
landcoverDir string
landCoverUrbanDepth string
landCoverIceShelvesDepth string
landCoverGlaciatedDepth string
pbfDir string
pbfSlicesDir string
mbtilesDir string
logsDir string
temp string
}
var pth = paths{}
func initDirStructure() {
tmp, err := os.MkdirTemp(os.TempDir(), "*")
if err != nil {
log.Printf("Unable to create temp dir: %s", err)
os.Exit(exitPermissions)
}
pth.workingDir = convertAbs(cfg.WorkingDir)
makeDir(pth.workingDir)
pth.outDir = convertAbs(cfg.OutDir)
makeDir(pth.outDir)
if !cfg.ExcludeOcean {
pth.coastlineDir = filepath.Join(pth.workingDir, "coastline")
makeDir(pth.coastlineDir)
} else {
pth.coastlineDir = filepath.Join(tmp, "coastline")
}
if !cfg.ExcludeLanduse {
pth.landcoverDir = filepath.Join(pth.workingDir, "landcover")
makeDir(pth.landcoverDir)
} else {
pth.landcoverDir = filepath.Join(tmp, "landcover")
}
pth.landCoverUrbanDepth = filepath.Join(pth.landcoverDir, "ne_10m_urban_areas")
makeDir(pth.landCoverUrbanDepth)
pth.landCoverIceShelvesDepth = filepath.Join(pth.landcoverDir, "ne_10m_antarctic_ice_shelves_polys")
makeDir(pth.landCoverIceShelvesDepth)
pth.landCoverGlaciatedDepth = filepath.Join(pth.landcoverDir, "ne_10m_glaciated_areas")
makeDir(pth.landCoverGlaciatedDepth)
pth.pbfDir = filepath.Join(pth.workingDir, "pbf")
makeDir(pth.pbfDir)
pth.pbfSlicesDir = filepath.Join(pth.pbfDir, "slices")
makeDir(pth.pbfSlicesDir)
pth.mbtilesDir = filepath.Join(pth.workingDir, "mbtiles")
makeDir(pth.mbtilesDir)
pth.logsDir = filepath.Join(pth.workingDir, "logs")
makeDir(pth.logsDir)
if system.DockerIsSnap() {
log.Println("snap version of docker detected; using local tmp folder since snap docker cannot access system /tmp")
pth.temp = filepath.Join(pth.workingDir, "tmp")
} else {
ucd := system.UserCacheDir()
if ucd != "" {
pth.temp = filepath.Join(system.UserCacheDir(), "sequentially-generate-planet-mbtiles")
} else {
pth.temp = filepath.Join(pth.workingDir, "tmp")
}
}
makeDir(pth.temp)
}
func convertAbs(path string) string {
if path == "" {
return ""
}
p, err := filepath.Abs(path)
if err != nil {
log.Fatal(err)
}
return p
}
func makeDir(fldr string) {
if err := os.MkdirAll(fldr, os.ModePerm); err != nil {
log.Printf("Unable to create %s Dir", fldr)
os.Exit(exitPermissions)
}
system.SetUserOwner(fldr)
}