Skip to content

Commit

Permalink
mirror the input directory struct in zip
Browse files Browse the repository at this point in the history
  • Loading branch information
rainu committed Oct 10, 2018
1 parent bab68bc commit 1559d2d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
7 changes: 3 additions & 4 deletions backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ func (b *backupManager) Create(files []string, description, vaultName string) *B

//store content direct into db
b.dbRepository.AddContent(dbBackupEntity, &model.Content{
ZipPath: content.Zippath,
RealPath: content.Realpath,
Length: content.Length,
ModTime: content.FileInfo.ModTime(),
Path: content.Realpath,
Length: content.Length,
ModTime: content.FileInfo.ModTime(),
})
}
}()
Expand Down
2 changes: 1 addition & 1 deletion backup/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_ZipEncryptDecryptUnzip(t *testing.T) {
go func() {
defer dstZip.Close()

Zip("./", dstZip, nil)
Zip([]string{"./"}, dstZip, nil)
}()

encodedZipFile, err := ioutil.TempFile("", ".enc")
Expand Down
7 changes: 4 additions & 3 deletions backup/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ func Zip(filePaths []string, dst io.Writer, contentChan chan<- *ZipContent) {
defer zipWriter.Close()

for _, filePath := range filePaths {
absFilePath, _ := filepath.Abs(filePath)
fInfo, err := os.Stat(filePath)
if err != nil {
LogFatal("Could not read file information for '%s'. Error: %v", filePath, err)
}

if fInfo.IsDir() {
addFiles(zipWriter, filePath, "", contentChan)
addFiles(zipWriter, absFilePath+"/", filepath.Dir(absFilePath+"/")+"/", contentChan)
} else {
dir, name := filepath.Split(filePath)
addFile(zipWriter, dir, "", name, contentChan)
dir, name := filepath.Split(absFilePath)
addFile(zipWriter, dir, dir+"/", name, contentChan)
}
}

Expand Down
6 changes: 2 additions & 4 deletions cli/action_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func (a *actionShow) Do(cfg *config.Config) {
}

tbl, err := prettytable.NewTable(
prettytable.Column{Header: "ZIP_PATH"},
prettytable.Column{Header: "REAL_PATH"},
prettytable.Column{Header: "PATH"},
prettytable.Column{Header: "LENGTH"},
)
if err != nil {
Expand All @@ -43,8 +42,7 @@ func (a *actionShow) Do(cfg *config.Config) {
}

err := tbl.AddRow(
content.ZipPath,
content.RealPath,
content.Path,
content.Length)
if err != nil {
panic(err)
Expand Down
3 changes: 1 addition & 2 deletions database/model/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ type Backup struct {
type Content struct {
ID uint `gorm:"primary_key"`
BackupID uint
ZipPath string `db:"zip_path" gorm:"type:TEXT"`
RealPath string `db:"real_path" gorm:"type:TEXT"`
Path string `db:"path" gorm:"type:TEXT"`
Length int64 `db:"length"`
ModTime time.Time `db:"mod"`
}

0 comments on commit 1559d2d

Please sign in to comment.