Skip to content

Update the in-place modification APIs#172

Open
clalancette wants to merge 9 commits into
masterfrom
clalancette/update-in-place
Open

Update the in-place modification APIs#172
clalancette wants to merge 9 commits into
masterfrom
clalancette/update-in-place

Conversation

@clalancette

Copy link
Copy Markdown
Owner

After heavy debugging on #171 , I've come to the conclusion that the APIs around updating data are incorrect. In particular, it is too easy to misuse modify_file_in_place when using the other APIs. Thus this PR does the following:

  1. Zero-pads directory records. This is mostly a bug-fix for when a record shrinks.
  2. Makes sure to propagate directory record shrinks all the way to the root. Again, a bug fix for when a directory record shrinks so all parents, grandparents, etc also get shrunken appropriately.
  3. Update the dotdot data length for modify_file_in_place. Again a bug fix to make sure dotdot length is always correct.
  4. Emit DeprecationWarning from actually deprecated APIs.
  5. Add a new API to the main PyCdlib class called update_file_contents. This allows the user to update file contents, ready for mastering. This was technically possible before by calling a rm_file followed by an add_file with the same filename and new contents, but this is more ergonomic.
  6. Add in a completely new contextmanager class called InPlaceEditor, which allows modifying things in place. This is the new API users should use if they want to modify in place. Also in here, I've deprecated modify_file_in_place from the main PyCdlib class.

Directory records depend on seeing a zero entry to stop
parsing.  But in the case that we *shrunk* a directory
record, we were failing to zero out old entries.  That
means we could have invalid or "ghost" directory entries.
Fix this by zero-padding directory records, and add
tests for this problem.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
When shrinking a directory record, it is possible that
we use fewer extents now, and thus we need to shrink
the grandparent.  That can cascade all the way up the
tree.  Fix this by walking back up the whole tree, rewriting
extents.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
modify_file_in_place was correctly updating the dot entry
data length, but not the subdirectory dotdot entries.
Fix that here by walking into all subdirectories.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Six PyCdlib methods carried a "(deprecated)" note in their docstrings
but had no runtime signal: get_and_write, get_and_write_fp,
add_joliet_directory, rm_joliet_directory, list_dir, and get_entry.
Have each emit a DeprecationWarning pointing at its replacement so
callers can find and migrate them.

Also hide their warnings in the tests; once we remove these
deprecated methods, we can remove these tests as well.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
These are a convenience that allow users to update the
file contents in an existing file.  It is pretty much
syntactic sugar; you could achieve the same effect via
rm_file/add_file, but this is more convenient.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Doing modify_file_in_place inside of the main PyCdlib
class was a mistake; it is too easy to misuse it and
mix it together with the other APIs which modify things
in memory and only write out at the end.  Instead, we
add in a new InPlaceEditor contextmanager, and users
have to use it from within that.

While doing this we also end up deprecating modify_file_in_place
with an eye towards eventually removing it.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant