|
@@ -42,7 +42,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
|
|
Versions: []*FileSnapshot{},
|
|
Versions: []*FileSnapshot{},
|
|
}
|
|
}
|
|
//Example folder structure: ./.localver/{date_time}/{file}
|
|
//Example folder structure: ./.localver/{date_time}/{file}
|
|
- expectedVersionFiles := filepath.Join(filepath.Dir(realFilepath), ".localver", "*", filepath.Base(realFilepath))
|
|
|
|
|
|
+ expectedVersionFiles := filepath.Join(filepath.Dir(realFilepath), ".metadata/.localver", "*", filepath.Base(realFilepath))
|
|
versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
|
|
versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
|
|
if err != nil {
|
|
if err != nil {
|
|
return &versionList, err
|
|
return &versionList, err
|
|
@@ -61,7 +61,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
|
|
ModTime: mtime,
|
|
ModTime: mtime,
|
|
OverwriteTime: overwriteDisplayTime,
|
|
OverwriteTime: overwriteDisplayTime,
|
|
Filesize: filesystem.GetFileSize(version),
|
|
Filesize: filesystem.GetFileSize(version),
|
|
- Relpath: ".localver/" + historyID + "/" + filepath.Base(version),
|
|
|
|
|
|
+ Relpath: ".metadata/.localver/" + historyID + "/" + filepath.Base(version),
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -69,7 +69,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func RestoreFileHistory(originalFilepath string, histroyID string) error {
|
|
func RestoreFileHistory(originalFilepath string, histroyID string) error {
|
|
- expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
|
|
|
|
|
|
+ expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
|
|
if !filesystem.FileExists(expectedVersionFile) {
|
|
if !filesystem.FileExists(expectedVersionFile) {
|
|
return errors.New("File version not exists")
|
|
return errors.New("File version not exists")
|
|
}
|
|
}
|
|
@@ -91,7 +91,7 @@ func RestoreFileHistory(originalFilepath string, histroyID string) error {
|
|
os.Remove(originalFilepath + ".backup")
|
|
os.Remove(originalFilepath + ".backup")
|
|
|
|
|
|
//Delete all history versions that is after the restored versions
|
|
//Delete all history versions that is after the restored versions
|
|
- expectedVersionFiles := filepath.Join(filepath.Dir(originalFilepath), ".localver", "*", filepath.Base(originalFilepath))
|
|
|
|
|
|
+ expectedVersionFiles := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", "*", filepath.Base(originalFilepath))
|
|
versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
|
|
versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -119,7 +119,7 @@ func RestoreFileHistory(originalFilepath string, histroyID string) error {
|
|
}
|
|
}
|
|
|
|
|
|
func RemoveFileHistory(originalFilepath string, histroyID string) error {
|
|
func RemoveFileHistory(originalFilepath string, histroyID string) error {
|
|
- expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
|
|
|
|
|
|
+ expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
|
|
if !filesystem.FileExists(expectedVersionFile) {
|
|
if !filesystem.FileExists(expectedVersionFile) {
|
|
return errors.New("File version not exists")
|
|
return errors.New("File version not exists")
|
|
}
|
|
}
|
|
@@ -128,7 +128,7 @@ func RemoveFileHistory(originalFilepath string, histroyID string) error {
|
|
}
|
|
}
|
|
|
|
|
|
func RemoveAllRelatedFileHistory(originalFilepath string) error {
|
|
func RemoveAllRelatedFileHistory(originalFilepath string) error {
|
|
- expectedVersionFiles, err := filepath.Glob(filepath.Join(filepath.Dir(originalFilepath), ".localver", "*", filepath.Base(originalFilepath)))
|
|
|
|
|
|
+ expectedVersionFiles, err := filepath.Glob(filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", "*", filepath.Base(originalFilepath)))
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -144,9 +144,11 @@ func CreateFileSnapshot(realFilepath string) error {
|
|
}
|
|
}
|
|
//Create the snapshot folder for this file
|
|
//Create the snapshot folder for this file
|
|
snapshotID := time.Now().Format("2006-01-02_15-04-05")
|
|
snapshotID := time.Now().Format("2006-01-02_15-04-05")
|
|
- expectedSnapshotFolder := filepath.Join(filepath.Dir(realFilepath), ".localver", snapshotID)
|
|
|
|
- os.MkdirAll(expectedSnapshotFolder, 0775)
|
|
|
|
-
|
|
|
|
|
|
+ expectedSnapshotFolder := filepath.Join(filepath.Dir(realFilepath), ".metadata/.localver", snapshotID)
|
|
|
|
+ err := os.MkdirAll(expectedSnapshotFolder, 0775)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
//Copy the target file to snapshot dir
|
|
//Copy the target file to snapshot dir
|
|
targetVersionFilepath := filepath.Join(expectedSnapshotFolder, filepath.Base(realFilepath))
|
|
targetVersionFilepath := filepath.Join(expectedSnapshotFolder, filepath.Base(realFilepath))
|
|
return filesystem.BasicFileCopy(realFilepath, targetVersionFilepath)
|
|
return filesystem.BasicFileCopy(realFilepath, targetVersionFilepath)
|