aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-18 12:47:59 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-18 14:30:02 +0100
commitc521b1cb1bfa338dd77cb27c60787e570d4557b1 (patch)
tree90241675a6fa31e64fbe54caadf3445bacbe1cff
parentinstaller: refactor custom actions to appear in chronological order (diff)
downloadwireguard-windows-c521b1cb1bfa338dd77cb27c60787e570d4557b1.tar.xz
wireguard-windows-c521b1cb1bfa338dd77cb27c60787e570d4557b1.zip
conf: do not remigrate configs that are pending deletion
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--conf/migration_windows.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/conf/migration_windows.go b/conf/migration_windows.go
index c5915b11..643d05c9 100644
--- a/conf/migration_windows.go
+++ b/conf/migration_windows.go
@@ -15,6 +15,7 @@ import (
"strings"
"golang.org/x/sys/windows"
+ "golang.org/x/sys/windows/registry"
"golang.org/x/sys/windows/svc/mgr"
)
@@ -31,22 +32,33 @@ func maybeMigrateConfiguration(c string) {
if err != nil {
return
}
+ pendingDeletion := make(map[string]bool)
+ if key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager`, registry.READ); err == nil {
+ if ntPaths, _, err := key.GetStringsValue("PendingFileRenameOperations"); err == nil {
+ for _, ntPath := range ntPaths {
+ pendingDeletion[strings.ToLower(strings.TrimPrefix(ntPath, `\??\`))] = true
+ }
+ }
+ key.Close()
+ }
migratedConfigs := make(map[string]string)
for i := range files {
if files[i].IsDir() {
continue
}
fileName := files[i].Name()
- newPath := filepath.Join(c, fileName)
- newFile, err := os.OpenFile(newPath, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
- if err != nil {
+ oldPath := filepath.Join(oldC, fileName)
+ if pendingDeletion[strings.ToLower(oldPath)] {
continue
}
- oldPath := filepath.Join(oldC, fileName)
oldConfig, err := ioutil.ReadFile(oldPath)
if err != nil {
- newFile.Close()
- os.Remove(newPath)
+ continue
+ }
+
+ newPath := filepath.Join(c, fileName)
+ newFile, err := os.OpenFile(newPath, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
+ if err != nil {
continue
}
_, err = newFile.Write(oldConfig)