-
Notifications
You must be signed in to change notification settings - Fork 195
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
Fix OpenStudio Windows crashed during save attempt #4026
Conversation
Depends on NREL/OpenStudio#4026
Depends on NREL/OpenStudio#4026
Windows is offline, and mac is failing on the usual suspect |
{ | ||
LOG_FREE(Error, "replaceDir", "Could not create destination directory: " << toString(dest)); | ||
return false; | ||
if (!openstudio::filesystem::exists(dest)) { |
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.
@macumber As far as I can tell you're actually no longer trying to remove the directory itself above (should you be after you tried removing everything inside?), so this block is pointless no?
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.
No I think you can hit this if you open a bare OSM file with no companion directory, the companion directory would be created in temp and then would be synched back.
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.
Good point!
} catch (const std::exception &e) { | ||
LOG_FREE(Error, "replaceDir", "Destination directory could not be removed: " << toString(dest) << "error: " << e.what()); | ||
return false; | ||
for (openstudio::filesystem::directory_iterator end_dir_it, it(dest); it != end_dir_it; ++it) { |
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.
So before: try to remove entire companion dir.
Now : try to remove all files directly under companion dir, and all subfolders.
To avoid more problems (eg a single file is opened with a handle on it in the files/ subfolder), we should do the same logic recursively, no?
Make safeDeleteDir() function or something: if file try delete, if directory call safeDeleteDir.
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.
Yeah I think that would work too, but the main thing is don't throw an unhandled exception if we try to delete something (file or folder) and it fails. Just log the file and return false. We should try to clean out as many files as we can.
@macumber Thanks for the fix for this! I know many app users will be very happy as this has been frustrating when saving your work only to have it crash. This looks good to drop to me. |
Pull request overview
replaceDir
will throw an uncaught exception if the user has the save directory (or child subdirectory) open in Windows explorer. This change no longer deletes the save directory if that exists, it clears all contents inside of it. Code attempts to sync as many changes as possible and does not generate uncaught exceptions.Pull Request Author
src/openstudio_lib/library/OpenStudioPolicy.xml
)Review Checklist
This will not be exhaustively relevant to every PR.