Add clean function to manager
This commit is contained in:
parent
56d80c4883
commit
c55ce0562c
64
manager.go
64
manager.go
|
@ -38,16 +38,32 @@ func (game *Game) Clean() error {
|
|||
return cachePathError
|
||||
}
|
||||
|
||||
var deployedListPath = filepath.Join(cachePath, "backup", "deployed.txt")
|
||||
var deployedListPath = filepath.Join(cachePath, "deployed.txt")
|
||||
|
||||
if backupFile, openError := os.Open(deployedListPath); !(os.IsNotExist(openError)) {
|
||||
defer backupFile.Close()
|
||||
if deployedListFile, openError := os.Open(deployedListPath); !(os.IsNotExist(openError)) {
|
||||
{
|
||||
defer deployedListFile.Close()
|
||||
|
||||
var scanner = bufio.NewScanner(backupFile)
|
||||
var deployedListScanner = bufio.NewScanner(deployedListFile)
|
||||
|
||||
for scanner.Scan() {
|
||||
var
|
||||
for deployedListScanner.Scan() {
|
||||
var deployedPath = filepath.Join(game.Path, deployedListScanner.Text())
|
||||
|
||||
if removeError := os.Remove(deployedPath); removeError != nil {
|
||||
return removeError
|
||||
}
|
||||
|
||||
var deployedDirPath = filepath.Dir(deployedPath)
|
||||
|
||||
if remainingDirEntries, readDirError := os.ReadDir(deployedDirPath); (readDirError == nil) && (len(remainingDirEntries) == 0) {
|
||||
if removeError := os.Remove(deployedDirPath); removeError != nil {
|
||||
return removeError
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
os.Truncate(deployedListPath, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -70,32 +86,35 @@ func (game *Game) ConfigPath() (string, error) {
|
|||
}
|
||||
|
||||
func (game *Game) Deploy() error {
|
||||
if cleanError := game.Clean(); cleanError != nil {
|
||||
return cleanError
|
||||
}
|
||||
|
||||
var cachePath, cachePathError = game.CachePath()
|
||||
|
||||
if cachePathError != nil {
|
||||
return cachePathError
|
||||
}
|
||||
|
||||
var deployedListFile, deployedListCreateError = os.Create(
|
||||
filepath.Join(cachePath, "deployed.txt"))
|
||||
|
||||
if deployedListCreateError != nil {
|
||||
return deployedListCreateError
|
||||
}
|
||||
|
||||
defer deployedListFile.Close()
|
||||
|
||||
{
|
||||
var configPath, configPathError = game.ConfigPath()
|
||||
|
||||
if configPathError != nil {
|
||||
return configPathError
|
||||
}
|
||||
|
||||
var backupPath = filepath.Join(cachePath, "backup")
|
||||
var deployedListPath = filepath.Join(backupPath, "deployed.txt")
|
||||
|
||||
if backupFile, openError := os.Open(deployedListPath); !(os.IsNotExist(openError)) {
|
||||
defer backupFile.Close()
|
||||
|
||||
var scanner = bufio.NewScanner(backupFile)
|
||||
|
||||
for scanner.Scan() {
|
||||
var
|
||||
}
|
||||
}
|
||||
|
||||
var deployedListWriter = bufio.NewWriter(deployedListFile)
|
||||
var modsPath = filepath.Join(configPath, "mods")
|
||||
var restorePath = filepath.Join(cachePath, "restore")
|
||||
|
||||
for i := range game.ModOrder {
|
||||
var mod = game.ModOrder[i]
|
||||
|
@ -136,7 +155,7 @@ func (game *Game) Deploy() error {
|
|||
|
||||
defer sourceFile.Close()
|
||||
|
||||
var targetFile, targetOpenError = os.Create(backupPath)
|
||||
var targetFile, targetOpenError = os.Create(filepath.Join(restorePath, localPath))
|
||||
|
||||
if targetOpenError != nil {
|
||||
return targetOpenError
|
||||
|
@ -154,6 +173,10 @@ func (game *Game) Deploy() error {
|
|||
if linkError := os.Link(path, linkPath); linkError != nil {
|
||||
return linkError
|
||||
}
|
||||
|
||||
if _, writeError := deployedListWriter.WriteString(linkPath); writeError != nil {
|
||||
return writeError
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -162,6 +185,7 @@ func (game *Game) Deploy() error {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue