Changeset 1b8ae80 in trunk


Ignore:
Timestamp:
2021-11-30T23:01:15Z (3 years ago)
Author:
meejah <meejah@…>
Branches:
master
Children:
0a4bc38
Parents:
3fd1ca8a
Message:

no auto-migrate; produce error if pickle-files exist

Location:
src/allmydata/storage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/storage/crawler.py

    r3fd1ca8a r1b8ae80  
    109109        pickle-style state into JSON-style state
    110110
    111     :returns unicode: the local path where the state is stored
     111    :returns FilePath: the local path where the state is stored
    112112
    113113    If this state path is JSON, simply return it.
     
    117117    """
    118118    if state_path.path.endswith(".json"):
    119         return state_path.path
     119        return state_path
    120120
    121121    json_state_path = state_path.siblingExtension(".json")
     
    124124    # nothing to upgrade
    125125    if not state_path.exists():
    126         return json_state_path.path
     126        return json_state_path
    127127
    128128    # upgrade the pickle data to JSON
     
    136136    # we've written the JSON, delete the pickle
    137137    state_path.remove()
    138     return json_state_path.path
     138    return json_state_path
     139
     140
     141def _confirm_json_format(fp):
     142    """
     143    :param FilePath fp: the original (pickle) name of a state file
     144
     145    This confirms that we do _not_ have the pickle-version of a
     146    state-file and _do_ either have nothing, or the JSON version. If
     147    the pickle-version exists, an exception is raised.
     148
     149    :returns FilePath: the JSON name of a state file
     150    """
     151    jsonfp = fp.siblingExtension(".json")
     152    if fp.exists():
     153        raise MigratePickleFileError(fp)
     154    return jsonfp
    139155
    140156
     
    147163
    148164    def __init__(self, state_path):
    149         self._path = FilePath(
    150             _maybe_upgrade_pickle_to_json(
    151                 FilePath(state_path),
    152                 _convert_pickle_state_to_json,
    153             )
    154         )
     165        self._path = _confirm_json_format(FilePath(state_path))
    155166
    156167    def load(self):
  • TabularUnified src/allmydata/storage/expirer.py

    r3fd1ca8a r1b8ae80  
    1313from allmydata.storage.crawler import (
    1414    ShareCrawler,
     15    MigratePickleFileError,
     16    _confirm_json_format,
    1517    _maybe_upgrade_pickle_to_json,
    1618    _convert_cycle_data,
     
    4143    """
    4244    Serialize the 'history' file of the lease-crawler state. This is
    43     "storage/history.state" for the pickle or
    44     "storage/history.state.json" for the new JSON format.
     45    "storage/lease_checker.history" for the pickle or
     46    "storage/lease_checker.history.json" for the new JSON format.
    4547    """
    4648
    4749    def __init__(self, history_path):
    48         self._path = FilePath(
    49             _maybe_upgrade_pickle_to_json(
    50                 FilePath(history_path),
    51                 _convert_pickle_state_to_json,
    52             )
    53         )
     50        self._path = _confirm_json_format(FilePath(history_path))
     51
    5452        if not self._path.exists():
    5553            with self._path.open("wb") as f:
Note: See TracChangeset for help on using the changeset viewer.