-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add GetOldestFolder and test * Add GetFileCount * Add test for remove file * Add removeOldElvuiFolder * Add RemoveOldestWtfZip * Add retention_rate * Add RemoveOldestWtfZip to main.go * Add testing skip for GH actions. These are manually tested
Showing
8 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"wowtools/utilities" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func RemoveOldestWtfZip() { | ||
retentionRate := viper.GetInt("retention_rate") | ||
wtfBackupDir := viper.GetString("backup_dir") + "WTF\\" | ||
fileCount := utilities.GetFileCount(wtfBackupDir) | ||
if fileCount > retentionRate { | ||
oldestFile := utilities.GetOldestFolder(wtfBackupDir) | ||
os.Chdir(wtfBackupDir) | ||
removeFile := os.Remove(oldestFile) | ||
if removeFile != nil { | ||
log.Fatal() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestCleanFolders(t *testing.T) { | ||
t.Skip() | ||
filepath := "C:\\Program Files (x86)\\World of Warcraft\\_retail_\\Backups\\WTF" | ||
var oldestFile fs.FileInfo | ||
files, err := ioutil.ReadDir(filepath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
oldestTime := time.Now() | ||
for _, file := range files { | ||
if file.Mode().IsRegular() && file.ModTime().Before(oldestTime) { | ||
oldestFile = file | ||
oldestTime = file.ModTime() | ||
} | ||
} | ||
if oldestFile == nil { | ||
err = os.ErrNotExist | ||
} | ||
fmt.Println(oldestFile.Name()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
"wowtools/utilities" | ||
) | ||
|
||
func TestRemoveFile(t *testing.T) { | ||
t.Skip() | ||
os.Chdir("C:\\Temp\\wowtools") | ||
testFile, err := os.Create("Test.txt") | ||
if err != nil { | ||
log.Fatal() | ||
} | ||
t.Log(testFile) | ||
testFile.Close() | ||
|
||
retentionRate := 1 | ||
fileCount := utilities.GetFileCount("C:\\Temp\\wowtools\\") | ||
t.Log(fileCount) | ||
if fileCount > retentionRate { | ||
oldestFile := utilities.GetOldestFolder("C:\\Temp\\wowtools") | ||
t.Log(oldestFile) | ||
removeFile := os.Remove(oldestFile) | ||
if removeFile != nil { | ||
log.Fatal() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters