mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 15:32:39 +00:00
no auto-migrate; produce error if pickle-files exist
This commit is contained in:
parent
3fd1ca8acb
commit
1b8ae8039e
@ -108,7 +108,7 @@ def _maybe_upgrade_pickle_to_json(state_path, convert_pickle):
|
|||||||
:param Callable[dict] convert_pickle: function to change
|
:param Callable[dict] convert_pickle: function to change
|
||||||
pickle-style state into JSON-style state
|
pickle-style state into JSON-style state
|
||||||
|
|
||||||
:returns unicode: the local path where the state is stored
|
:returns FilePath: the local path where the state is stored
|
||||||
|
|
||||||
If this state path is JSON, simply return it.
|
If this state path is JSON, simply return it.
|
||||||
|
|
||||||
@ -116,14 +116,14 @@ def _maybe_upgrade_pickle_to_json(state_path, convert_pickle):
|
|||||||
JSON path.
|
JSON path.
|
||||||
"""
|
"""
|
||||||
if state_path.path.endswith(".json"):
|
if state_path.path.endswith(".json"):
|
||||||
return state_path.path
|
return state_path
|
||||||
|
|
||||||
json_state_path = state_path.siblingExtension(".json")
|
json_state_path = state_path.siblingExtension(".json")
|
||||||
|
|
||||||
# if there's no file there at all, we're done because there's
|
# if there's no file there at all, we're done because there's
|
||||||
# nothing to upgrade
|
# nothing to upgrade
|
||||||
if not state_path.exists():
|
if not state_path.exists():
|
||||||
return json_state_path.path
|
return json_state_path
|
||||||
|
|
||||||
# upgrade the pickle data to JSON
|
# upgrade the pickle data to JSON
|
||||||
import pickle
|
import pickle
|
||||||
@ -135,7 +135,23 @@ def _maybe_upgrade_pickle_to_json(state_path, convert_pickle):
|
|||||||
|
|
||||||
# we've written the JSON, delete the pickle
|
# we've written the JSON, delete the pickle
|
||||||
state_path.remove()
|
state_path.remove()
|
||||||
return json_state_path.path
|
return json_state_path
|
||||||
|
|
||||||
|
|
||||||
|
def _confirm_json_format(fp):
|
||||||
|
"""
|
||||||
|
:param FilePath fp: the original (pickle) name of a state file
|
||||||
|
|
||||||
|
This confirms that we do _not_ have the pickle-version of a
|
||||||
|
state-file and _do_ either have nothing, or the JSON version. If
|
||||||
|
the pickle-version exists, an exception is raised.
|
||||||
|
|
||||||
|
:returns FilePath: the JSON name of a state file
|
||||||
|
"""
|
||||||
|
jsonfp = fp.siblingExtension(".json")
|
||||||
|
if fp.exists():
|
||||||
|
raise MigratePickleFileError(fp)
|
||||||
|
return jsonfp
|
||||||
|
|
||||||
|
|
||||||
class _LeaseStateSerializer(object):
|
class _LeaseStateSerializer(object):
|
||||||
@ -146,12 +162,7 @@ class _LeaseStateSerializer(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, state_path):
|
def __init__(self, state_path):
|
||||||
self._path = FilePath(
|
self._path = _confirm_json_format(FilePath(state_path))
|
||||||
_maybe_upgrade_pickle_to_json(
|
|
||||||
FilePath(state_path),
|
|
||||||
_convert_pickle_state_to_json,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
"""
|
"""
|
||||||
|
@ -12,6 +12,8 @@ import os
|
|||||||
import struct
|
import struct
|
||||||
from allmydata.storage.crawler import (
|
from allmydata.storage.crawler import (
|
||||||
ShareCrawler,
|
ShareCrawler,
|
||||||
|
MigratePickleFileError,
|
||||||
|
_confirm_json_format,
|
||||||
_maybe_upgrade_pickle_to_json,
|
_maybe_upgrade_pickle_to_json,
|
||||||
_convert_cycle_data,
|
_convert_cycle_data,
|
||||||
)
|
)
|
||||||
@ -40,17 +42,13 @@ def _convert_pickle_state_to_json(state):
|
|||||||
class _HistorySerializer(object):
|
class _HistorySerializer(object):
|
||||||
"""
|
"""
|
||||||
Serialize the 'history' file of the lease-crawler state. This is
|
Serialize the 'history' file of the lease-crawler state. This is
|
||||||
"storage/history.state" for the pickle or
|
"storage/lease_checker.history" for the pickle or
|
||||||
"storage/history.state.json" for the new JSON format.
|
"storage/lease_checker.history.json" for the new JSON format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, history_path):
|
def __init__(self, history_path):
|
||||||
self._path = FilePath(
|
self._path = _confirm_json_format(FilePath(history_path))
|
||||||
_maybe_upgrade_pickle_to_json(
|
|
||||||
FilePath(history_path),
|
|
||||||
_convert_pickle_state_to_json,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if not self._path.exists():
|
if not self._path.exists():
|
||||||
with self._path.open("wb") as f:
|
with self._path.open("wb") as f:
|
||||||
json.dump({}, f)
|
json.dump({}, f)
|
||||||
|
Loading…
Reference in New Issue
Block a user