[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sandboxed-tor-browser/master] Store the version of the sandbox in the config file, and re-Sync() the config, and reinstall the `mozilla.cfg` when things change.



commit c168f0854cec19a55d5401ae822c450e64760ef7
Author: Yawning Angel <yawning@xxxxxxxxxxxxxxx>
Date:   Sun Dec 18 03:57:12 2016 +0000

    Store the version of the sandbox in the config file, and re-Sync() the config, and reinstall the `mozilla.cfg` when things change.
    
    This is version + revision based, which should aid in debugging, and
    help to ensure that the various configuration bits and peices are in a
    coherent state.
---
 ChangeLog                                               |  2 ++
 .../sandboxed-tor-browser/internal/ui/config/config.go  | 17 ++++++++++++++---
 src/cmd/sandboxed-tor-browser/internal/ui/ui.go         | 10 +++++++++-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5555cce..68d5376 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@ Changes in version 0.0.3 - UNRELEASED:
    on certain pages.
  * Bug 20973: Silence Gdk warnings on systems with integrated png loader.
  * Bug 20806: Try even harder to exclude gstreamer.
+ * Store the version of the sandbox in the config file, and re-Sync() the
+   config, and reinstall the `mozilla.cfg` when things change.
  * Include the git revision as a static asset, and display it as part of
    the `--version` output.
  * Fix a nil pointer deref on SIGINT received durring bootstrap.
diff --git a/src/cmd/sandboxed-tor-browser/internal/ui/config/config.go b/src/cmd/sandboxed-tor-browser/internal/ui/config/config.go
index d0af260..f9a0b1a 100644
--- a/src/cmd/sandboxed-tor-browser/internal/ui/config/config.go
+++ b/src/cmd/sandboxed-tor-browser/internal/ui/config/config.go
@@ -313,6 +313,10 @@ type Config struct {
 	// FirstLuach is set for the first launch post install.
 	FirstLaunch bool `json:"firstLaunch"`
 
+	// LastVersion is the last `sandboxed-tor`browser` version that wrote
+	// the config file.
+	LastVersion string `json:"lastVersion"`
+
 	// UseSystemTor indicates if a system tor daemon should be used.
 	UseSystemTor bool `json:"-"`
 
@@ -337,6 +341,10 @@ type Config struct {
 	// ConfigDir is `XDG_CONFIG_HOME/appDir`.
 	ConfigDir string `json:"-"`
 
+	// ConfigVersionChanged indicates that the config file was from an old
+	// version.
+	ConfigVersionChanged bool `json:"-"`
+
 	isDirty      bool
 	path         string
 	manifestPath string
@@ -417,7 +425,7 @@ func (cfg *Config) ResetDirty() {
 
 // New creates a new config object and populates it with the configuration
 // from disk if available, default values otherwise.
-func New() (*Config, error) {
+func New(version string) (*Config, error) {
 	const (
 		envControlPort = "TOR_CONTROL_PORT"
 		envRuntimeDir  = "XDG_RUNTIME_DIR"
@@ -483,16 +491,19 @@ func New() (*Config, error) {
 	}
 
 	// Load the config file.
+	cfg.isDirty = true
 	if b, err := ioutil.ReadFile(cfg.path); err != nil {
 		// File not found, or failed to read.
 		if !os.IsNotExist(err) {
 			return nil, err
 		}
-		cfg.isDirty = true
 	} else if err = json.Unmarshal(b, &cfg); err != nil {
 		return nil, err
+	} else if cfg.LastVersion != version {
+		// The version changed, we want to re-Sync().
+		cfg.LastVersion = version
+		cfg.ConfigVersionChanged = true
 	} else {
-		// File exists and was successfully deserialized.
 		cfg.isDirty = false
 	}
 
diff --git a/src/cmd/sandboxed-tor-browser/internal/ui/ui.go b/src/cmd/sandboxed-tor-browser/internal/ui/ui.go
index 969d7c0..cd3767c 100644
--- a/src/cmd/sandboxed-tor-browser/internal/ui/ui.go
+++ b/src/cmd/sandboxed-tor-browser/internal/ui/ui.go
@@ -122,7 +122,7 @@ func (c *Common) Init() error {
 	flag.StringVar(&c.logPath, "l", "", "Specify a log file.")
 
 	// Initialize/load the config file.
-	if c.Cfg, err = config.New(); err != nil {
+	if c.Cfg, err = config.New(Version + "-" + Revision); err != nil {
 		return err
 	}
 	if c.Manif, err = config.LoadManifest(c.Cfg); err != nil {
@@ -140,6 +140,14 @@ func (c *Common) Init() error {
 		BundleChannels[c.Cfg.Architecture] = channels
 	}
 
+	// If the config is clearly from an old version, re-assert our will over
+	// firefox, by re-writing the autoconfig files.
+	if c.Cfg.ConfigVersionChanged {
+		if err = writeAutoconfig(c.Cfg); err != nil {
+			return err
+		}
+	}
+
 	if c.Manif != nil {
 		if err = c.Manif.Sync(); err != nil {
 			return err

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits