Commit fe58b1f
authored
fix: create output directory if it doesn't exist (#567)
* fix: allow non-existent output directories with --output flag
When using the --output flag, PerfSpect now accepts and creates
directories that don't exist yet, rather than requiring them to exist
beforehand. The directory is created early during initialization to
validate write permissions before data collection begins, preventing
wasted effort if the directory cannot be created.
Changes:
- Removed existence check that prevented specifying new directories
- Added early directory creation after logging setup
- Validates write access before any data collection starts
- Provides clear error messages if creation fails
Benefits:
- Improved usability - no manual directory creation needed
- Fail-fast validation - catches permission/disk issues immediately
- No wasted data collection - validates before work begins
- Creates nested directories automatically (e.g., /path/to/new/dir)
- Consistent with default output directory behavior
The directory is created at an optimal point in initialization:
- After basic setup (logging) is complete, so errors can be logged
- Before setting app context and starting any data collection
- Early enough to fail fast and save user time
Common failure modes handled gracefully:
- Permission denied - clear error before any work
- Disk full - detected immediately
- Read-only filesystem - fails at start
- Path conflicts (file exists) - caught early
Fixes #556
Signed-off-by: Jason Harper <jason.m.harper@intel.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
* fix: allow non-existent output directories with --output flag
When using the --output flag, PerfSpect now accepts and creates
directories that don't exist yet, rather than requiring them to exist
beforehand. The directory is created once, early during initialization,
to validate write permissions before data collection begins.
Changes:
- Removed existence check in initializeApplication()
- Added createOutputDir() function in root.go (single use, kept local)
- Create output directory early (after logging, before data collection)
- Only log creation when directory is actually created
- Removed redundant directory creation calls from commands
- Detects if output path exists as a file and fails with clear error
Benefits:
- Improved usability - no manual directory creation needed
- Fail-fast validation - catches permission/disk issues immediately
- No wasted data collection - validates write access before work begins
- Single point of directory creation - simpler, more maintainable
- Cleaner logs - only logs when directory is actually created
- Creates nested directories automatically (e.g., /path/to/new/dir)
Directory creation timing:
- After logging is configured (errors can be logged)
- Before app context is set and data collection starts
- Early enough to fail fast and save time
Error handling:
- Permission denied - clear error before any work
- Disk full - detected immediately
- Read-only filesystem - fails at start
- Path exists as file - caught with clear error
- Path already exists as directory - succeeds silently
Fixes #556
Signed-off-by: Jason Harper <jason.m.harper@intel.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
---------
Signed-off-by: Jason Harper <jason.m.harper@intel.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>1 parent ea021c9 commit fe58b1f
3 files changed
+39
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | 845 | | |
854 | | - | |
| 846 | + | |
855 | 847 | | |
856 | 848 | | |
857 | 849 | | |
| |||
1057 | 1049 | | |
1058 | 1050 | | |
1059 | 1051 | | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | 1052 | | |
1071 | 1053 | | |
1072 | 1054 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
149 | 173 | | |
150 | 174 | | |
151 | | - | |
| 175 | + | |
152 | 176 | | |
153 | 177 | | |
154 | 178 | | |
| |||
157 | 181 | | |
158 | 182 | | |
159 | 183 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | 184 | | |
170 | | - | |
| 185 | + | |
171 | 186 | | |
172 | 187 | | |
173 | 188 | | |
| |||
220 | 235 | | |
221 | 236 | | |
222 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
223 | 249 | | |
224 | 250 | | |
225 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | 207 | | |
216 | 208 | | |
217 | | - | |
| 209 | + | |
218 | 210 | | |
219 | 211 | | |
220 | 212 | | |
| |||
289 | 281 | | |
290 | 282 | | |
291 | 283 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | 284 | | |
302 | 285 | | |
303 | 286 | | |
| |||
0 commit comments