Fix: Create config directory before writing#2757
Fix: Create config directory before writing#2757jmcouffin merged 3 commits intopyrevitlabs:developfrom
Conversation
Ensures the destination directory exists before writing the config file. When setting up the user config file from a template, the code did not ensure that the destination directory existed before attempting to write the file. This would cause an error if the directory did not exist, which is the case for a new user. This change adds a call to `CommonUtils.EnsurePath` to create the directory if it does not exist.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where pyRevit would fail to create a user configuration file for new users because the destination directory might not exist. The fix ensures the configuration directory is created before attempting to write the config file.
Key Changes
- Added a directory creation check before writing the configuration file
- Prevents errors when setting up config files for new users who don't have the config directory yet
There was a problem hiding this comment.
PR Summary:
This PR fixes a bug where pyRevit fails to create user config files for new users. The issue occurs when the destination directory doesn't exist in %AppData%\pyRevit\. The fix adds a single line to ensure the directory exists before writing the config file.
Review Summary:
The fix is well-targeted and correctly addresses the reported issue #2595. The solution uses the existing CommonUtils.EnsurePath method, which is the appropriate utility for ensuring directory existence before file operations. The change is minimal, defensive, and follows established patterns in the codebase. No critical issues were identified.
Follow-up suggestions:
- @devloai consider creating a unit test to verify config file creation works correctly when the destination directory doesn't exist
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25230+1701-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0824-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0848-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0859-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25232+1126-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25232+1352-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25233+0639-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25233+1431-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25233+1438-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25237+0821-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25237+0841-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1124-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1535-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1604-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25238+0615-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25240+1356-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25240+1743-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1636-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1639-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25268+1757-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1336-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1431-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1436-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1822-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25271+1719-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2003-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2012-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2017-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2149-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25274+1734-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1425-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1427-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25279+2157-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+0218-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1054-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1057-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25282+1656-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25283+0140-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25286+1022-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25287+0905-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25287+1000-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25288+0613-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25293+0755-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25293+0828-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25293+1113-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25293+1234-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25295+0707-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25296+0824-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0949-wip |
Ensures the destination directory exists before writing the config file.
When setting up the user config file from a template, the code did not ensure that the destination directory existed before attempting to write the file. This would cause an error if the directory did not exist, which is the case for a new user.
This change adds a call to
CommonUtils.EnsurePathto create the directory if it does not exist.Trying to fix #2595