Stage exports and swap on success instead of rmtree up front#26
Merged
Conversation
…ront Export To Files previously ran shutil.rmtree on the target folder before writing anything. A locked folder (open Explorer window, IDE, git client, antivirus) aborted the export at the start, and a mid-export crash left the on-disk copy destroyed with no replacement. The export now writes into <target>.codescribe_staging and is swapped in only after it completes: the old target is renamed to <target>.codescribe_backup, the staging folder is renamed to the target, and the backup is deleted (a failure deleting the backup only prints a warning). If a rename fails because the target is locked, the staged files are synced into the target file by file instead; files that disappeared from staging are not deleted. If the sync also fails, ExportFolderLockedError reports the staging folder path where the completed export is preserved. Credit: reimplemented from ipfedor/codescribe commits bc6ec89, 1141d7d. Refs #24.
Contributor
Author
|
Live validation on CODESYS V3.5 SP11, automated via --runscript. All scenarios passed
|
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #24. Reimplemented (not copied) from ipfedor/codescribe commits bc6ec89 and 1141d7d.
Behaviour
Export To Filespreviously ranshutil.rmtreeon the target folder before writing anything. A locked target folder (open Explorer window, IDE, git client, antivirus) aborted the export at the start, and a mid-export crash left the on-disk copy destroyed with no replacement.The export now writes into
<target>.codescribe_stagingand the target is only touched after the export completes, infinalize_export_folder:<target>.codescribe_backup, rename staging to the target, delete the backup. A failure deleting the backup only prints a warning; the export still succeeds.os.walk, creating missing directories and overwriting existing files. Files that disappeared from staging are not deleted. The staging folder is then removed and the sync path is reported in the message view.ExportFolderLockedErroris raised and the error dialog names the target, says it is likely locked by another program, gives the staging folder path where the completed export is preserved, and includes the original error. Nothing is lost.A stale staging folder from a previous failed run is removed at the start of the next export.
Live validation required before merge
.codescribe_stagingor.codescribe_backupfolders left behind.Stacked on #25; retargets to
mainautomatically when that merges.