freezetag icon indicating copy to clipboard operation
freezetag copied to clipboard

Fix #6: check path matches, rather than blindly selecting metadata

Open joshbarrass opened this issue 1 year ago • 1 comments

Fixes #6 by checking the path within each entry with a matching checksum to ensure it matches the path of the file we're currently opening. Tested and confirmed working on Linux, and should work on any Posix system. Needs testing on Windows.

More Detailed Explanation

Previously, it was assumed in freezefs that the first freezetag entry with a matching checksum corresponded to the correct metadata. However, this is not a valid assumption, and this edge case is correctly handled by the thaw command but not by the mount command. To rectify this, the target_path is generated from the path stored in the frozen_entry, which is of the form /freezetag_root/path/to/file.ext. Correct me if this assumption is wrong, but from my testing it seems that any file referenced by a freezetag file, regardless of where it is stored on the real filesystem or where it is stored relative to the freezetag file, is added to the freezefs at its relative path from the root directory stored in the freezetag file (though one possible edge case I can think of is a freezetag file where the root is /). The first two components of this path, / and freezetag_root are removed, and the remaining parts, path, to and file.ext are joined into path/to/file.ext. This matches the form of the path in each entry of freezetag.data.frozen.files, so we can compare the two paths whenever the checksum matches to ensure we are selecting the correct metadata.

This solution will need testing on Windows, as I am not sure whether joining the parts of the path using the / character is appropriate. I am not sure exactly how the freezetag.data.frozen.files paths are represented on a Windows system. It may be necessary to join the paths using os.path.sep instead. Unfortunately, I do not have a Windows computer to hand with the correct environment to test this myself, so if someone else could test this, that would be great.

joshbarrass avatar Apr 26 '23 22:04 joshbarrass

In my tests, I have tested:

  • a FLAC file in the freezetag root
  • a FLAC file in a subdirectory of the freezetag root

If there are any other test cases that would be worth looking at, let me know and I will try them.

joshbarrass avatar Apr 26 '23 22:04 joshbarrass