Skip to content

Commit

Permalink
all: Fix versioning path handling (#7407)
Browse files Browse the repository at this point in the history
  • Loading branch information
imsodin committed Feb 26, 2021
1 parent a69afc9 commit fff8805
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 72 deletions.
5 changes: 0 additions & 5 deletions gui/default/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ angular.module('syncthing.core')
simpleKeep: 5,
staggeredMaxAge: 365,
staggeredCleanInterval: 3600,
versionsPath: "",
externalCommand: "",
};

Expand Down Expand Up @@ -1912,9 +1911,6 @@ angular.module('syncthing.core')

$scope.currentFolder._guiVersioning.cleanupIntervalS = +currentVersioning.cleanupIntervalS;
$scope.currentFolder._guiVersioning.selector = currentVersioning.type;
if (currentVersioning.type !== 'external') {
$scope.currentFolder._guiVersioning.versionsPath = currentVersioning.params.versionsPath;
}

// Apply parameters currently in use
switch (currentVersioning.type) {
Expand Down Expand Up @@ -2053,7 +2049,6 @@ angular.module('syncthing.core')
folderCfg.versioning.type = folderCfg._guiVersioning.selector;
if ($scope.internalVersioningEnabled()) {
folderCfg.versioning.cleanupIntervalS = folderCfg._guiVersioning.cleanupIntervalS;
folderCfg.versioning.versionsPath = folderCfg._guiVersioning.versionsPath;
}
switch (folderCfg._guiVersioning.selector) {
case "trashcan":
Expand Down
4 changes: 2 additions & 2 deletions gui/default/syncthing/folder/editFolderModalView.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
</p>
</div>
<div class="form-group" ng-if="internalVersioningEnabled()">
<label translate for="versionsPath">Versions Path</label>
<input name="versionsPath" id="versionsPath" class="form-control" type="text" ng-model="currentFolder._guiVersioning.versionsPath" />
<label translate for="fsPath">Versions Path</label>
<input name="fsPath" id="fsPath" class="form-control" type="text" ng-model="currentFolder.versioning.fsPath" />
<p translate class="help-block">Path where versions should be stored (leave empty for the default .stversions directory in the shared folder).</p>
</div>
<div class="form-group" ng-if="currentFolder._guiVersioning.selector=='external'" ng-class="{'has-error': folderEditor.externalCommand.$invalid && folderEditor.externalCommand.$dirty}">
Expand Down
5 changes: 0 additions & 5 deletions gui/default/untrusted/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ angular.module('syncthing.core')
simpleKeep: 5,
staggeredMaxAge: 365,
staggeredCleanInterval: 3600,
versionsPath: "",
externalCommand: "",
};

Expand Down Expand Up @@ -1943,9 +1942,6 @@ angular.module('syncthing.core')

$scope.currentFolder._guiVersioning.cleanupIntervalS = +currentVersioning.cleanupIntervalS;
$scope.currentFolder._guiVersioning.selector = currentVersioning.type;
if (currentVersioning.type !== 'external') {
$scope.currentFolder._guiVersioning.versionsPath = currentVersioning.params.versionsPath;
}

// Apply parameters currently in use
switch (currentVersioning.type) {
Expand Down Expand Up @@ -2093,7 +2089,6 @@ angular.module('syncthing.core')
folderCfg.versioning.type = folderCfg._guiVersioning.selector;
if ($scope.internalVersioningEnabled()) {
folderCfg.versioning.cleanupIntervalS = folderCfg._guiVersioning.cleanupIntervalS;
folderCfg.versioning.versionsPath = folderCfg._guiVersioning.versionsPath;
}
switch (folderCfg._guiVersioning.selector) {
case "trashcan":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
</p>
</div>
<div class="form-group" ng-if="internalVersioningEnabled()">
<label translate for="versionsPath">Versions Path</label>
<input name="versionsPath" id="versionsPath" class="form-control" type="text" ng-model="currentFolder._guiVersioning.versionsPath" />
<label translate for="fsPath">Versions Path</label>
<input name="fsPath" id="fsPath" class="form-control" type="text" ng-model="currentFolder.versioning.fsPath" />
<p translate class="help-block">Path where versions should be stored (leave empty for the default .stversions directory in the shared folder).</p>
</div>
<div class="form-group" ng-if="currentFolder._guiVersioning.selector=='external'" ng-class="{'has-error': folderEditor.externalCommand.$invalid && folderEditor.externalCommand.$dirty}">
Expand Down
2 changes: 1 addition & 1 deletion lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
OldestHandledVersion = 10
CurrentVersion = 34
CurrentVersion = 35
MaxRescanIntervalS = 365 * 24 * 60 * 60
)

Expand Down
19 changes: 19 additions & 0 deletions lib/config/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
// put the newest on top for readability.
var (
migrations = migrationSet{
{35, migrateToConfigV35},
{34, migrateToConfigV34},
{33, migrateToConfigV33},
{32, migrateToConfigV32},
Expand Down Expand Up @@ -93,6 +94,24 @@ func (m migration) apply(cfg *Configuration) {
cfg.Version = m.targetVersion
}

func migrateToConfigV35(cfg *Configuration) {
for i, fcfg := range cfg.Folders {
params := fcfg.Versioning.Params
if params["fsType"] != "" {
var fsType fs.FilesystemType
_ = fsType.UnmarshalText([]byte(params["fsType"]))
cfg.Folders[i].Versioning.FSType = fsType
}
if params["versionsPath"] != "" && params["fsPath"] == "" {
params["fsPath"] = params["versionsPath"]
}
cfg.Folders[i].Versioning.FSPath = params["fsPath"]
delete(cfg.Folders[i].Versioning.Params, "fsType")
delete(cfg.Folders[i].Versioning.Params, "fsPath")
delete(cfg.Folders[i].Versioning.Params, "versionsPath")
}
}

func migrateToConfigV34(cfg *Configuration) {
cfg.Defaults.Folder.Path = cfg.Options.DeprecatedDefaultFolderPath
cfg.Options.DeprecatedDefaultFolderPath = ""
Expand Down
13 changes: 10 additions & 3 deletions lib/config/versioningconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
"encoding/xml"
"sort"

"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/util"
)

// internalVersioningConfiguration is used in XML serialization
type internalVersioningConfiguration struct {
Type string `xml:"type,attr,omitempty"`
Params []internalParam `xml:"param"`
CleanupIntervalS int `xml:"cleanupIntervalS" default:"3600"`
Type string `xml:"type,attr,omitempty"`
Params []internalParam `xml:"param"`
CleanupIntervalS int `xml:"cleanupIntervalS" default:"3600"`
FSPath string `xml:"fsPath"`
FSType fs.FilesystemType `xml:"fsType"`
}

type internalParam struct {
Expand Down Expand Up @@ -64,6 +67,8 @@ func (c *VersioningConfiguration) toInternal() internalVersioningConfiguration {
var tmp internalVersioningConfiguration
tmp.Type = c.Type
tmp.CleanupIntervalS = c.CleanupIntervalS
tmp.FSPath = c.FSPath
tmp.FSType = c.FSType
for k, v := range c.Params {
tmp.Params = append(tmp.Params, internalParam{k, v})
}
Expand All @@ -76,6 +81,8 @@ func (c *VersioningConfiguration) toInternal() internalVersioningConfiguration {
func (c *VersioningConfiguration) fromInternal(intCfg internalVersioningConfiguration) {
c.Type = intCfg.Type
c.CleanupIntervalS = intCfg.CleanupIntervalS
c.FSPath = intCfg.FSPath
c.FSType = intCfg.FSType
c.Params = make(map[string]string, len(intCfg.Params))
for _, p := range intCfg.Params {
c.Params[p.Key] = p.Val
Expand Down
139 changes: 110 additions & 29 deletions lib/config/versioningconfiguration.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions lib/versioner/staggered.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func newStaggered(cfg config.FolderConfiguration) Versioner {
maxAge = 31536000 // Default: ~1 year
}

// Backwards compatibility
params["fsPath"] = params["versionsPath"]
versionsFs := versionerFsFromFolderCfg(cfg)

s := &staggered{
Expand Down
6 changes: 2 additions & 4 deletions lib/versioner/staggered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ func TestCreateVersionPath(t *testing.T) {
ID: "default",
Path: tmpDir,
Versioning: config.VersioningConfiguration{
Type: "staggered",
Params: map[string]string{
"versionsPath": versionsDir,
},
Type: "staggered",
FSPath: versionsDir,
},
}

Expand Down
7 changes: 3 additions & 4 deletions lib/versioner/trashcan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ func TestTrashcanArchiveRestoreSwitcharoo(t *testing.T) {
FilesystemType: fs.FilesystemTypeBasic,
Path: tmpDir1,
Versioning: config.VersioningConfiguration{
Params: map[string]string{
"fsType": "basic",
"fsPath": tmpDir2,
},
FSType: fs.FilesystemTypeBasic,
FSPath: tmpDir2,
},
}
folderFs := cfg.Filesystem()
Expand Down Expand Up @@ -101,6 +99,7 @@ func TestTrashcanArchiveRestoreSwitcharoo(t *testing.T) {
}

func readFile(t *testing.T, filesystem fs.Filesystem, name string) string {
t.Helper()
fd, err := filesystem.Open(name)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit fff8805

Please sign in to comment.