Commit 2cf99e0
committed
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 <[email protected]>
Signed-off-by: Harper, Jason M <[email protected]>1 parent 1b5d660 commit 2cf99e0
3 files changed
+30
-39
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 | | |
| |||
213 | 237 | | |
214 | 238 | | |
215 | 239 | | |
216 | | - | |
| 240 | + | |
217 | 241 | | |
218 | 242 | | |
219 | 243 | | |
220 | 244 | | |
221 | 245 | | |
222 | | - | |
| 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