1.6 KiB
Phase 7
Supporting single-file (as opposed to folder) drawers has introduced a bug, which will require some refactoring to fix. The basic problem is a confusion over where to open a single-file drawer to, the filename specified in the target path (including the default name rules on that) or the filename in the tarball.
The desired behavior is that if a target path is specified, it should be what's validated and used. If a target path is not specified, the default should be:
- For a single-file drawer, the filename of the single file in the drawer
- For a folder drawer, a folder named after the drawer file (without extension)
In order to make this work, we'll need to refactor to move some of the validation into perform_open, since we can't check whether the target path is valid (or even know what it is) until we first load and decrypt the drawer.
Let's do the following:
target_pathnow needs to be anOption<PathBuf>and we can get rid oftarget_inferredbecausetarget_pathbeing None means the same thing.- Let's make a
default_targetmethod which returns what the default target would be for a given DrawerOperation, to encapsulate these default rules (and put a nice comment above it explaining the rules). validate_openshould no longer attempt to validate the target path.perform_opennow needs to figure out a target path using the newdefault_targetmethod (ortarget_pathif present) and can do the validation there.
As an aside, is there any duplicated logic between validate_open and validate_close as far as checking the drawer file
path? Can any of that be extracted into a method?