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

Handle zero byte registry.json file #2435

Merged
merged 1 commit into from
May 15, 2018

Conversation

HebaruSan
Copy link
Member

Problem

If your registry.json file is zero bytes long, CKAN crashes on load:

image

Cause

RegistryManager approaches registry creation by trying to load registry.json and then creating a new file if an exception is thrown during the load attempt. If the file contains a valid registry, it is simply loaded. If it doesn't exist, then a missing file exception is caught and the file is created.

If the file exists but is empty, then no exceptions are thrown, but the registry reference is set to null. Later, we attempt to use this reference, which causes an exception that isn't caught.

I was not able to figure out a way that a zero-byte file could be created. It might have something to do with the ChinhDo.Transactions library that CKAN uses for some filesystem access; I looked into this library at one point, and it essentially creates a temp folder and then copies files in/out of it, so maybe weird things can happen with files if something goes wrong with that.

Changes

Now if the attempt to load returns a null reference, we fall back to Registry.Empty(). This allows the load attempt to complete without errors, and the application will work as normal.

A test is added to check that loading an empty registry file generates an empty registry without exceptions.

Fixes #2433.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Pull request Tests Issues affecting the internal tests Registry Issues affecting the registry and removed Bug Something is not working as intended labels Apr 28, 2018
@politas politas merged commit fc05476 into KSP-CKAN:master May 15, 2018
politas added a commit that referenced this pull request May 15, 2018
@HebaruSan HebaruSan deleted the fix/zero-byte-registry branch May 15, 2018 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Registry Issues affecting the registry Tests Issues affecting the internal tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants