diff --git a/backup/manager.go b/backup/manager.go index 1293455..fda0642 100644 --- a/backup/manager.go +++ b/backup/manager.go @@ -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(), }) } }() diff --git a/backup/manager_test.go b/backup/manager_test.go index d28c654..c7fc156 100644 --- a/backup/manager_test.go +++ b/backup/manager_test.go @@ -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") diff --git a/backup/zip.go b/backup/zip.go index a1478f1..36ab07b 100644 --- a/backup/zip.go +++ b/backup/zip.go @@ -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) } } diff --git a/cli/action_show.go b/cli/action_show.go index c48bdb8..1195eeb 100644 --- a/cli/action_show.go +++ b/cli/action_show.go @@ -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 { @@ -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) diff --git a/database/model/backup.go b/database/model/backup.go index a1dcabb..209b479 100644 --- a/database/model/backup.go +++ b/database/model/backup.go @@ -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"` }