forked from steeve/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.go
54 lines (46 loc) · 1.37 KB
/
migration.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
package main
import (
"compress/gzip"
"io"
"os"
"path/filepath"
"github.com/steeve/pulsar/config"
"github.com/steeve/pulsar/repository"
)
func Migrate() {
firstRun := filepath.Join(config.Get().Info.Path, ".firstrun")
if _, err := os.Stat(firstRun); err == nil {
return
}
file, _ := os.Create(firstRun)
defer file.Close()
log.Info("Preparing for first run")
// Move ga client id file out of the cache directory
gaFile := filepath.Join(config.Get().Info.Profile, "cache", "io.steeve.pulsar.ga")
if _, err := os.Stat(gaFile); err == nil {
os.Rename(gaFile, filepath.Join(config.Get().Info.Profile, "io.steeve.pulsar.ga"))
}
gaFile = filepath.Join(config.Get().Info.Profile, "io.steeve.pulsar.ga")
if file, err := os.Open(gaFile); err == nil {
if gzReader, err := gzip.NewReader(file); err != nil {
outFile, _ := os.Create(gaFile + ".gz")
gzWriter := gzip.NewWriter(outFile)
file.Seek(0, os.SEEK_SET)
io.Copy(gzWriter, file)
gzWriter.Flush()
gzWriter.Close()
outFile.Close()
file.Close()
os.Rename(gaFile+".gz", gaFile)
} else {
gzReader.Close()
}
}
// Remove the cache
log.Info("Clearing cache")
os.RemoveAll(filepath.Join(config.Get().Info.Profile, "cache"))
log.Info("Creating Pulsar Repository Addon")
if err := repository.MakePulsarRepositoryAddon(); err != nil {
log.Error("Unable to create repository addon: %s", err)
}
}