forked from TrueCloudLab/restic
isMountPointExcluded to isMountPointIncluded
This commit is contained in:
parent
24330c19a8
commit
90b168eb6c
2 changed files with 20 additions and 22 deletions
|
@ -145,22 +145,20 @@ func (fs *LocalVss) Lstat(name string) (os.FileInfo, error) {
|
||||||
return os.Lstat(fs.snapshotPath(name))
|
return os.Lstat(fs.snapshotPath(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// isMountPointExcluded is true if given mountpoint excluded by user.
|
// isMountPointIncluded is true if given mountpoint included by user.
|
||||||
func (fs *LocalVss) isMountPointExcluded(mountPoint string) bool {
|
func (fs *LocalVss) isMountPointIncluded(mountPoint string) bool {
|
||||||
if fs.excludeVolumes == nil {
|
if fs.excludeVolumes == nil {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
volume, err := GetVolumeNameForVolumeMountPoint(mountPoint)
|
volume, err := GetVolumeNameForVolumeMountPoint(mountPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.msgError(mountPoint, errors.Errorf("failed to get volume from mount point [%s]: %s", mountPoint, err))
|
fs.msgError(mountPoint, errors.Errorf("failed to get volume from mount point [%s]: %s", mountPoint, err))
|
||||||
|
return true
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := fs.excludeVolumes[strings.ToLower(volume)]
|
_, ok := fs.excludeVolumes[strings.ToLower(volume)]
|
||||||
|
return !ok
|
||||||
return ok
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapshotPath returns the path inside a VSS snapshots if it already exists.
|
// snapshotPath returns the path inside a VSS snapshots if it already exists.
|
||||||
|
@ -199,20 +197,20 @@ func (fs *LocalVss) snapshotPath(path string) string {
|
||||||
if !snapshotExists && !snapshotFailed {
|
if !snapshotExists && !snapshotFailed {
|
||||||
vssVolume := volumeNameLower + string(filepath.Separator)
|
vssVolume := volumeNameLower + string(filepath.Separator)
|
||||||
|
|
||||||
if fs.isMountPointExcluded(vssVolume) {
|
if !fs.isMountPointIncluded(vssVolume) {
|
||||||
fs.msgMessage("snapshots for [%s] excluded by user\n", vssVolume)
|
fs.msgMessage("snapshots for [%s] excluded by user\n", vssVolume)
|
||||||
fs.failedSnapshots[volumeNameLower] = struct{}{}
|
fs.failedSnapshots[volumeNameLower] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
fs.msgMessage("creating VSS snapshot for [%s]\n", vssVolume)
|
fs.msgMessage("creating VSS snapshot for [%s]\n", vssVolume)
|
||||||
|
|
||||||
var filter VolumeFilter
|
var includeVolume VolumeFilter
|
||||||
if !fs.excludeAllMountPoints {
|
if !fs.excludeAllMountPoints {
|
||||||
filter = func(volume string) bool {
|
includeVolume = func(volume string) bool {
|
||||||
return !fs.isMountPointExcluded(volume)
|
return fs.isMountPointIncluded(volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if snapshot, err := NewVssSnapshot(fs.provider, vssVolume, fs.timeout, filter, fs.msgError); err != nil {
|
if snapshot, err := NewVssSnapshot(fs.provider, vssVolume, fs.timeout, includeVolume, fs.msgError); err != nil {
|
||||||
fs.msgError(vssVolume, errors.Errorf("failed to create snapshot for [%s]: %s",
|
fs.msgError(vssVolume, errors.Errorf("failed to create snapshot for [%s]: %s",
|
||||||
vssVolume, err))
|
vssVolume, err))
|
||||||
fs.failedSnapshots[volumeNameLower] = struct{}{}
|
fs.failedSnapshots[volumeNameLower] = struct{}{}
|
||||||
|
|
|
@ -154,10 +154,10 @@ func TestParseMountPoints(t *testing.T) {
|
||||||
sysVolumeMatch,
|
sysVolumeMatch,
|
||||||
},
|
},
|
||||||
[]check{
|
[]check{
|
||||||
{`c:\`, true},
|
{`c:\`, false},
|
||||||
{`c:`, true},
|
{`c:`, false},
|
||||||
{sysVolume, true},
|
{sysVolume, false},
|
||||||
{sysVolumeMutated, true},
|
{sysVolumeMutated, false},
|
||||||
},
|
},
|
||||||
[]string{},
|
[]string{},
|
||||||
},
|
},
|
||||||
|
@ -169,10 +169,10 @@ func TestParseMountPoints(t *testing.T) {
|
||||||
sysVolumeMatch,
|
sysVolumeMatch,
|
||||||
},
|
},
|
||||||
[]check{
|
[]check{
|
||||||
{`c:\windows\`, false},
|
{`c:\windows\`, true},
|
||||||
{`\\?\Volume{39b9cac2-bcdb-4d51-97c8-0d0677d607fb}\`, false},
|
{`\\?\Volume{39b9cac2-bcdb-4d51-97c8-0d0677d607fb}\`, true},
|
||||||
{`c:`, true},
|
{`c:`, false},
|
||||||
{``, false},
|
{``, true},
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
`failed to parse vss\.exclude-volumes \[z:\\nonexistent\]:.*`,
|
`failed to parse vss\.exclude-volumes \[z:\\nonexistent\]:.*`,
|
||||||
|
@ -208,8 +208,8 @@ func TestParseMountPoints(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range test.checks {
|
for _, c := range test.checks {
|
||||||
if dst.isMountPointExcluded(c.volume) != c.result {
|
if dst.isMountPointIncluded(c.volume) != c.result {
|
||||||
t.Fatalf(`wrong check: isMountPointExcluded("%s") != %v`, c.volume, c.result)
|
t.Fatalf(`wrong check: isMountPointIncluded("%s") != %v`, c.volume, c.result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue