Skip to content

Commit 1387c1d

Browse files
committed
refactor: reformat code with gofumpt
1 parent f02253d commit 1387c1d

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

cmd/backmeup/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
"github.com/d-Rickyy-b/backmeup/internal/config"
1717
)
1818

19-
var VERBOSE bool
20-
var DEBUG bool
19+
var (
20+
VERBOSE bool
21+
DEBUG bool
22+
)
2123

2224
var (
2325
version = "dev"
@@ -113,7 +115,6 @@ func getFiles(sourcePath string, unit config.Unit) ([]archiver.BackupFileMetadat
113115
// validatePath checks if a certain file/directory exists
114116
func validatePath(path string, mustBeDir bool) bool {
115117
file, err := os.Stat(path)
116-
117118
if err != nil {
118119
if os.IsNotExist(err) {
119120
log.Printf("File '%s' does not exist.", path)
@@ -141,7 +142,7 @@ func writeBackup(filesToBackup []archiver.BackupFileMetadata, unit config.Unit)
141142

142143
if !pathExists {
143144
log.Printf("Backup path '%s' does not exist.\n", newBackupBasePath)
144-
mkdirErr := os.Mkdir(newBackupBasePath, 0777)
145+
mkdirErr := os.Mkdir(newBackupBasePath, 0o777)
145146

146147
if mkdirErr != nil {
147148
log.Fatalf("Can't create backup directory '%s'", newBackupBasePath)
@@ -151,8 +152,8 @@ func writeBackup(filesToBackup []archiver.BackupFileMetadata, unit config.Unit)
151152
backupBasePath = newBackupBasePath
152153
}
153154

154-
var counter = 0
155-
var backupExists = true
155+
counter := 0
156+
backupExists := true
156157
var backupArchiveName, backupArchivePath string
157158

158159
for backupExists {
@@ -303,7 +304,6 @@ func testExclusion(path string, config config.Config, unitNames []string) {
303304
} else {
304305
log.Printf("Path is not excluded by any of the tested units!")
305306
}
306-
307307
}
308308

309309
// printVersionString prints the full version string of backmeup

cmd/backmeup/main_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ func TestHandleExcludeFileGlob(t *testing.T) {
88
// Try to match a path with a single file glob
99
paths := []string{
1010
"/home/test/file.png",
11-
"/home/test/path/file.png"}
11+
"/home/test/path/file.png",
12+
}
1213
negativePaths := []string{
1314
"/home/test/file.jpg",
14-
"/home/test/path/test.exe"}
15+
"/home/test/path/test.exe",
16+
}
1517
pattern := "*.png"
1618

1719
for _, path := range paths {
@@ -33,7 +35,8 @@ func TestHandleExcludeSubDirectory(t *testing.T) {
3335
// Try to exclude any subdirectory called "test" and its content
3436
paths := []string{
3537
"/home/test/file.png",
36-
"/home/test/path/file.png"}
38+
"/home/test/path/file.png",
39+
}
3740
pattern := "**/test/**"
3841
// TODO using 'test/' as pattern should work as well
3942

@@ -114,7 +117,8 @@ func TestHandleExcludeDoubleWildcardAndWildcardFile(t *testing.T) {
114117
func TestHandleExcludeDoubleWildcardAndPartialWildcardFile(t *testing.T) {
115118
paths := []string{
116119
"/home/test/foo/file.png",
117-
"/home/test/bar/file.png"}
120+
"/home/test/bar/file.png",
121+
}
118122
pattern := "/home/**/f*.png"
119123

120124
for _, path := range paths {
@@ -126,7 +130,8 @@ func TestHandleExcludeDoubleWildcardAndPartialWildcardFile(t *testing.T) {
126130

127131
negativePath := []string{
128132
"/home/test/foo/test.png",
129-
"/home/test/foo/asdf.png"}
133+
"/home/test/foo/asdf.png",
134+
}
130135
for _, negativePath := range negativePath {
131136
negMatched := handleExclude(negativePath, pattern)
132137
if negMatched {
@@ -138,7 +143,8 @@ func TestHandleExcludeDoubleWildcardAndPartialWildcardFile(t *testing.T) {
138143
func TestHandleExcludeDoubleWildcardMultipleChildren(t *testing.T) {
139144
paths := []string{
140145
"/home/test1/path/file.png",
141-
"/home/test2/path/file.png"}
146+
"/home/test2/path/file.png",
147+
}
142148
pattern := "**/path/file.png"
143149

144150
for _, path := range paths {

internal/archiver/archive.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"archive/tar"
55
"errors"
66
"fmt"
7-
"github.com/cheggaaa/pb/v3"
8-
"github.com/d-Rickyy-b/backmeup/internal/config"
9-
"github.com/klauspost/compress/gzip"
10-
"github.com/klauspost/compress/zip"
117
"io"
128
"log"
139
"os"
1410
"path/filepath"
1511
"strings"
12+
13+
"github.com/cheggaaa/pb/v3"
14+
"github.com/d-Rickyy-b/backmeup/internal/config"
15+
"github.com/klauspost/compress/gzip"
16+
"github.com/klauspost/compress/zip"
1617
)
1718

1819
type BackupFileMetadata struct {

internal/config/config.go

-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ func (config Config) FromYaml(yamlData []byte) (Config, error) {
101101
// It returns true if it exists, otherwise false
102102
func validatePath(path string, mustBeDir bool) bool {
103103
file, err := os.Stat(path)
104-
105104
if err != nil {
106105
if os.IsNotExist(err) {
107106
log.Printf("File '%s' does not exist.", path)
@@ -154,7 +153,6 @@ func (config *Config) validate() error {
154153
func ReadConfig(configPath string) (Config, error) {
155154
log.Printf("Trying to read config file '%s'!", configPath)
156155
data, err := os.ReadFile(configPath)
157-
158156
if err != nil {
159157
log.Println("Can't read config file! Exiting!")
160158
os.Exit(1)

0 commit comments

Comments
 (0)