-
Notifications
You must be signed in to change notification settings - Fork 0
Update/operation tmp dirs #81
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
Conversation
|
||
class BaseDataOperation(ABC): | ||
|
||
def __init__(self, input_data: dict = None): | ||
""" The data inputs are passed in in the format described from the wizard_description """ | ||
self.input_data = self._normalize_input_data(input_data) | ||
self.cache_key = self.generate_cache_key() | ||
self.temp = settings.TEMP_FITS_DIR # default fallback | ||
|
||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't put this in the init for the data operation. There are several places in the server where we instantiate a data operation just to get its cache_key from an input set to check if its in the cache, where we never intend to do the operation. This code should just wrap the operate
method to create and destroy the temp dir I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
tmp_hash_path = os.path.join(self.temp, self.cache_key) | ||
# If tmp dir already exists, append a random hash to avoid collision | ||
if os.path.exists(tmp_hash_path): | ||
tmp_hash_path = os.path.join(tmp_hash_path, hashlib.sha256(os.urandom(8)).hexdigest()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be possible since its just the cache_key which should ensure we are only operating on it once... But I guess its fine to have as extra protection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking if someone ran the same operation on another computer at the same time: ex. Median on the same two images. Thought it might be more possible in a classroom setting. Is a very unique edge case though
Adds a
temp
attribute to the Data Operation base class that is cleaned up with a destructor when the class is garbage collected. Creates a dir unique to that operation so that any files created are removed at the end of an operation.Updated all operations to use this. It's more of a safety net since it only catches affineremap's extra files for now but its good security to make sure we're not leaving any leftover files after an operation.