properly handle and log legacy storage migration
@@ -19,18 +19,9 @@ class Storage:
self.config = py3_wrapper.config
py3_config = self.config.get('py3_config', {})
- # legacy storage cache
- legacy_path = ''
- config_path = py3_wrapper.config.get('i3status_config_path')
- if config_path:
- legacy_path = os.path.join(
- os.path.dirname(config_path), 'py3status.data'
- )
- if os.path.exists(legacy_path):
- new_path = os.path.expanduser('~/.cache/py3status_cache.data')
- os.rename(legacy_path, new_path)
- self.storage_path = legacy_path
- else:
+ # check for legacy storage cache
+ legacy_storage_path = self.get_legacy_storage_path()
+
# cutting edge storage cache
storage_config = py3_config.get('py3status', {}).get('storage')
if storage_config:
@@ -49,6 +40,15 @@ class Storage:
storage_dir = os.path.expanduser('~/.cache')
self.storage_path = os.path.join(storage_dir, storage_file)
+ # move legacy storage cache to new desired / default location
+ if legacy_storage_path:
+ self.py3_wrapper.log(
+ 'moving legacy storage_path {} to {}'.format(
+ legacy_storage_path, self.storage_path
+ )
+ )
+ os.rename(legacy_storage_path, self.storage_path)
+
try:
with open(self.storage_path, 'rb') as f:
try:
@@ -65,6 +65,19 @@ class Storage:
self.py3_wrapper.log('storage_data: {}'.format(self.data))
self.initialized = True
+ def get_legacy_storage_path(self):
+ """
+ Detect and return existing legacy storage path.
+ """
+ config_dir = os.path.dirname(
+ self.py3_wrapper.config.get('i3status_config_path', '/tmp')
+ )
+ storage_path = os.path.join(config_dir, 'py3status.data')
+ if os.path.exists(storage_path):
+ return storage_path
+ else:
+ return None
+
def save(self):
"""
Save our data to disk. We want to always have a valid file.
