Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync writes __source__ falsely into frozen layers #130

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
23.1.3+dev.2
* Fixed a bug where zodbsync was writing `source`-files into frozen
layers

23.1.2+dev.1
* Fix layer-update for cases where the last element in both checksum files is
not the same.
Expand Down
36 changes: 35 additions & 1 deletion perfact/zodbsync/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ def test_playback_hook_failed(self):
assert 'NewFolder2' not in self.app.objectIds()

@contextmanager
def addlayer(self, seqnum='00'):
def addlayer(self, seqnum='00', frozen=True):
"""
Create a temp directory and add a config that uses this as additional
code layer.
Expand All @@ -1666,6 +1666,7 @@ def addlayer(self, seqnum='00'):
with tempfile.TemporaryDirectory() as layer:
with open(path, 'w') as f:
f.write('base_dir = "{}"\n'.format(layer))
f.write('frozen = {}\n'.format(frozen))
os.mkdir(os.path.join(layer, '__root__'))
# Force re-reading config
if hasattr(self, 'runner'):
Expand Down Expand Up @@ -2152,3 +2153,36 @@ def test_layer_update_warn(self, caplog):
assert expect + '/Test' in caplog.text
assert 'AttributeError' not in caplog.text
assert expect + '/ToDelete/Sub' in caplog.text

def test_layer_frozen(self):
"""
Verify that changed files are properly written into the custom
layer in case the layer below is frozen.
"""
with self.runner.sync.tm:
self.app.manage_addProduct['OFSP'].manage_addFile(id='blob')

with self.addlayer(frozen=True) as layer:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure that frozen = True is the default for layers below the top-most custom layer. So not sure why this was necessary, but it still is OK.

self.run('record', '/blob')
shutil.move(
'{}/__root__/blob'.format(self.repo.path),
'{}/__root__/blob'.format(layer),
)
with self.runner.sync.tm:
self.app.blob.manage_edit(
filedata='text_content',
content_type='text/plain',
title='BLOB'
)
self.run('record', '/')
root = os.path.join(self.repo.path, '__root__')
# both meta and source file are in custom layer
assert os.path.exists(os.path.join(root, 'blob/__meta__'))
assert os.path.exists(os.path.join(root, 'blob/__source__.txt'))
source_fmt = '{}/__root__/blob/__source__.txt'
with open(source_fmt.format(layer)) as f:
# source in layer should still be empty
assert f.read() == ''
with open(source_fmt.format(self.repo.path)) as f:
# ... content is in custom layer!
assert f.read() == 'text_content'
3 changes: 1 addition & 2 deletions perfact/zodbsync/zodbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ def fs_write(self, path, data):
obj_id=path.rstrip('/').rsplit('/', 1)[-1],
)
src_fname = '{}.{}'.format(base, ext)
src_path = os.path.join(base_dir, src_fname)
new_data['src_fnames'] = [src_fname]
new_data['source'] = source

Expand All @@ -494,7 +493,7 @@ def fs_write(self, path, data):
self.logger.debug(
"Will write %d bytes of source" % len(source)
)
with open(src_path, 'wb') as f:
with open(os.path.join(write_base, src_fname), 'wb') as f:
f.write(source)

# We wrote the object to the topmost layer, so the index where the
Expand Down