|
|
@@ -852,7 +852,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
if config.DataRootDirectory == "" {
|
|
|
wd, err := os.Getwd()
|
|
|
if err != nil {
|
|
|
- return errors.Trace(err)
|
|
|
+ return errors.Trace(StripFilePathsError(err))
|
|
|
}
|
|
|
config.DataRootDirectory = wd
|
|
|
}
|
|
|
@@ -862,7 +862,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
if !common.FileExists(dataDirectoryPath) {
|
|
|
err := os.Mkdir(dataDirectoryPath, os.ModePerm)
|
|
|
if err != nil {
|
|
|
- return errors.Tracef("failed to create datastore directory %s with error: %s", dataDirectoryPath, err.Error())
|
|
|
+ return errors.Tracef("failed to create datastore directory with error: %s", StripFilePathsError(err, dataDirectoryPath))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -889,16 +889,19 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, "Config migration: need migration")
|
|
|
noticeMigrations := migrationsFromLegacyNoticeFilePaths(config)
|
|
|
|
|
|
+ successfulMigrations := 0
|
|
|
+
|
|
|
for _, migration := range noticeMigrations {
|
|
|
- err := common.DoFileMigration(migration)
|
|
|
+ err := DoFileMigration(migration)
|
|
|
if err != nil {
|
|
|
alertMsg := fmt.Sprintf("Config migration: %s", errors.Trace(err))
|
|
|
noticeMigrationAlertMsgs = append(noticeMigrationAlertMsgs, alertMsg)
|
|
|
} else {
|
|
|
- infoMsg := fmt.Sprintf("Config migration: moved %s to %s", migration.OldPath, migration.NewPath)
|
|
|
- noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, infoMsg)
|
|
|
+ successfulMigrations += 1
|
|
|
}
|
|
|
}
|
|
|
+ infoMsg := fmt.Sprintf("Config migration: %d/%d notice files successfully migrated", successfulMigrations, len(noticeMigrations))
|
|
|
+ noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, infoMsg)
|
|
|
} else {
|
|
|
noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, "Config migration: migration already completed")
|
|
|
}
|
|
|
@@ -966,7 +969,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
if !common.FileExists(dataStoreDirectoryPath) {
|
|
|
err := os.Mkdir(dataStoreDirectoryPath, os.ModePerm)
|
|
|
if err != nil {
|
|
|
- return errors.Tracef("failed to create datastore directory %s with error: %s", dataStoreDirectoryPath, err.Error())
|
|
|
+ return errors.Tracef("failed to create datastore directory with error: %s", StripFilePathsError(err, dataStoreDirectoryPath))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -975,7 +978,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
if !common.FileExists(oslDirectoryPath) {
|
|
|
err := os.Mkdir(oslDirectoryPath, os.ModePerm)
|
|
|
if err != nil {
|
|
|
- return errors.Tracef("failed to create osl directory %s with error: %s", oslDirectoryPath, err.Error())
|
|
|
+ return errors.Tracef("failed to create osl directory with error: %s", StripFilePathsError(err, oslDirectoryPath))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -990,7 +993,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
// Validate config fields.
|
|
|
|
|
|
if !common.FileExists(config.DataRootDirectory) {
|
|
|
- return errors.Tracef("DataRootDirectory does not exist: %s", config.DataRootDirectory)
|
|
|
+ return errors.TraceNew("DataRootDirectory does not exist")
|
|
|
}
|
|
|
|
|
|
if config.PropagationChannelId == "" {
|
|
|
@@ -1140,7 +1143,7 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
if err != nil {
|
|
|
return errors.Trace(err)
|
|
|
}
|
|
|
- NoticeInfo("MigrateDataStoreDirectory unset, using working directory %s", wd)
|
|
|
+ NoticeInfo("MigrateDataStoreDirectory unset, using working directory")
|
|
|
config.MigrateDataStoreDirectory = wd
|
|
|
}
|
|
|
|
|
|
@@ -1154,31 +1157,33 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
|
|
|
|
|
|
// Do migrations
|
|
|
|
|
|
+ successfulMigrations := 0
|
|
|
for _, migration := range migrations {
|
|
|
- err := common.DoFileMigration(migration)
|
|
|
+ err := DoFileMigration(migration)
|
|
|
if err != nil {
|
|
|
NoticeWarning("Config migration: %s", errors.Trace(err))
|
|
|
} else {
|
|
|
- NoticeInfo("Config migration: moved %s to %s", migration.OldPath, migration.NewPath)
|
|
|
+ successfulMigrations += 1
|
|
|
}
|
|
|
}
|
|
|
+ NoticeInfo(fmt.Sprintf("Config migration: %d/%d legacy files successfully migrated", successfulMigrations, len(migrations)))
|
|
|
|
|
|
// Remove OSL directory if empty
|
|
|
if config.MigrateObfuscatedServerListDownloadDirectory != "" {
|
|
|
files, err := ioutil.ReadDir(config.MigrateObfuscatedServerListDownloadDirectory)
|
|
|
if err != nil {
|
|
|
- NoticeWarning("Error reading OSL directory %s: %s", config.MigrateObfuscatedServerListDownloadDirectory, errors.Trace(err))
|
|
|
+ NoticeWarning("Error reading OSL directory: %s", errors.Trace(StripFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory)))
|
|
|
} else if len(files) == 0 {
|
|
|
err := os.Remove(config.MigrateObfuscatedServerListDownloadDirectory)
|
|
|
if err != nil {
|
|
|
- NoticeWarning("Error deleting empty OSL directory %s: %s", config.MigrateObfuscatedServerListDownloadDirectory, errors.Trace(err))
|
|
|
+ NoticeWarning("Error deleting empty OSL directory: %s", errors.Trace(StripFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory)))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
f, err := os.Create(migrationCompleteFilePath)
|
|
|
if err != nil {
|
|
|
- NoticeWarning("Config migration: failed to create %s with error %s", migrationCompleteFilePath, errors.Trace(err))
|
|
|
+ NoticeWarning("Config migration: failed to create migration completed file with error %s", errors.Trace(StripFilePathsError(err, migrationCompleteFilePath)))
|
|
|
} else {
|
|
|
NoticeInfo("Config migration: completed")
|
|
|
f.Close()
|
|
|
@@ -1845,24 +1850,27 @@ func (n *loggingNetworkIDGetter) GetNetworkID() string {
|
|
|
// with the legacy config fields HomepageNoticesFilename and
|
|
|
// RotatingNoticesFilename, to the new file paths used by Psiphon which exist
|
|
|
// under the data root directory.
|
|
|
-func migrationsFromLegacyNoticeFilePaths(config *Config) []common.FileMigration {
|
|
|
- var noticeMigrations []common.FileMigration
|
|
|
+func migrationsFromLegacyNoticeFilePaths(config *Config) []FileMigration {
|
|
|
+ var noticeMigrations []FileMigration
|
|
|
|
|
|
if config.MigrateHomepageNoticesFilename != "" {
|
|
|
- noticeMigrations = append(noticeMigrations, common.FileMigration{
|
|
|
+ noticeMigrations = append(noticeMigrations, FileMigration{
|
|
|
+ Name: "hompage",
|
|
|
OldPath: config.MigrateHomepageNoticesFilename,
|
|
|
NewPath: config.GetHomePageFilename(),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if config.MigrateRotatingNoticesFilename != "" {
|
|
|
- migrations := []common.FileMigration{
|
|
|
+ migrations := []FileMigration{
|
|
|
{
|
|
|
+ Name: "notices",
|
|
|
OldPath: config.MigrateRotatingNoticesFilename,
|
|
|
NewPath: config.GetNoticesFilename(),
|
|
|
IsDir: false,
|
|
|
},
|
|
|
{
|
|
|
+ Name: "notices.1",
|
|
|
OldPath: config.MigrateRotatingNoticesFilename + ".1",
|
|
|
NewPath: config.GetNoticesFilename() + ".1",
|
|
|
},
|
|
|
@@ -1877,14 +1885,17 @@ func migrationsFromLegacyNoticeFilePaths(config *Config) []common.FileMigration
|
|
|
// performed to move files from legacy file paths, which were configured with
|
|
|
// legacy config fields, to the new file paths used by Psiphon which exist
|
|
|
// under the data root directory.
|
|
|
-func migrationsFromLegacyFilePaths(config *Config) ([]common.FileMigration, error) {
|
|
|
+// Note: an attempt is made to redact any file paths from the returned error.
|
|
|
+func migrationsFromLegacyFilePaths(config *Config) ([]FileMigration, error) {
|
|
|
|
|
|
- migrations := []common.FileMigration{
|
|
|
+ migrations := []FileMigration{
|
|
|
{
|
|
|
+ Name: "psiphon.boltdb",
|
|
|
OldPath: filepath.Join(config.MigrateDataStoreDirectory, "psiphon.boltdb"),
|
|
|
NewPath: filepath.Join(config.GetDataStoreDirectory(), "psiphon.boltdb"),
|
|
|
},
|
|
|
{
|
|
|
+ Name: "psiphon.boltdb.lock",
|
|
|
OldPath: filepath.Join(config.MigrateDataStoreDirectory, "psiphon.boltdb.lock"),
|
|
|
NewPath: filepath.Join(config.GetDataStoreDirectory(), "psiphon.boltdb.lock"),
|
|
|
},
|
|
|
@@ -1894,16 +1905,19 @@ func migrationsFromLegacyFilePaths(config *Config) ([]common.FileMigration, erro
|
|
|
|
|
|
// Migrate remote server list files
|
|
|
|
|
|
- rslMigrations := []common.FileMigration{
|
|
|
+ rslMigrations := []FileMigration{
|
|
|
{
|
|
|
+ Name: "remote_server_list",
|
|
|
OldPath: config.MigrateRemoteServerListDownloadFilename,
|
|
|
NewPath: config.GetRemoteServerListDownloadFilename(),
|
|
|
},
|
|
|
{
|
|
|
+ Name: "remote_server_list.part",
|
|
|
OldPath: config.MigrateRemoteServerListDownloadFilename + ".part",
|
|
|
NewPath: config.GetRemoteServerListDownloadFilename() + ".part",
|
|
|
},
|
|
|
{
|
|
|
+ Name: "remote_server_list.part.etag",
|
|
|
OldPath: config.MigrateRemoteServerListDownloadFilename + ".part.etag",
|
|
|
NewPath: config.GetRemoteServerListDownloadFilename() + ".part.etag",
|
|
|
},
|
|
|
@@ -1923,11 +1937,12 @@ func migrationsFromLegacyFilePaths(config *Config) ([]common.FileMigration, erro
|
|
|
|
|
|
files, err := ioutil.ReadDir(config.MigrateObfuscatedServerListDownloadDirectory)
|
|
|
if err != nil {
|
|
|
- NoticeWarning("Migration: failed to read directory %s with error %s", config.MigrateObfuscatedServerListDownloadDirectory, err)
|
|
|
+ NoticeWarning("Migration: failed to read OSL download directory with error %s", StripFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory))
|
|
|
} else {
|
|
|
for _, file := range files {
|
|
|
if oslFileRegex.MatchString(file.Name()) {
|
|
|
- fileMigration := common.FileMigration{
|
|
|
+ fileMigration := FileMigration{
|
|
|
+ Name: "osl",
|
|
|
OldPath: filepath.Join(config.MigrateObfuscatedServerListDownloadDirectory, file.Name()),
|
|
|
NewPath: filepath.Join(config.GetObfuscatedServerListDownloadDirectory(), file.Name()),
|
|
|
}
|
|
|
@@ -1957,7 +1972,7 @@ func migrationsFromLegacyFilePaths(config *Config) ([]common.FileMigration, erro
|
|
|
|
|
|
files, err := ioutil.ReadDir(upgradeDownloadDir)
|
|
|
if err != nil {
|
|
|
- NoticeWarning("Migration: failed to read directory %s with error %s", upgradeDownloadDir, err)
|
|
|
+ NoticeWarning("Migration: failed to read upgrade download directory with error %s", StripFilePathsError(err, upgradeDownloadDir))
|
|
|
} else {
|
|
|
|
|
|
for _, file := range files {
|
|
|
@@ -1966,7 +1981,8 @@ func migrationsFromLegacyFilePaths(config *Config) ([]common.FileMigration, erro
|
|
|
|
|
|
oldFileSuffix := strings.TrimPrefix(file.Name(), oldUpgradeDownloadFilename)
|
|
|
|
|
|
- fileMigration := common.FileMigration{
|
|
|
+ fileMigration := FileMigration{
|
|
|
+ Name: "upgrade",
|
|
|
OldPath: filepath.Join(upgradeDownloadDir, file.Name()),
|
|
|
NewPath: config.GetUpgradeDownloadFilename() + oldFileSuffix,
|
|
|
}
|