mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 22:15:41 +00:00
This commit enhances the handling of the `-P /path` / `--PDFreportpath` option by ensuring that nwipe can create the specified directory if it does not already exist. Previously, nwipe simply called `access(path, W_OK)` and exited with a generic “not a writeable directory” error if the directory did not exist or was not writable. This caused ambiguity and prevented the use of custom report paths without pre-creating them externally. Key improvements: - Added a new helper function `nwipe_ensure_directory()` that: - Differentiates between “non-existent”, “not a directory”, and “not writable”. - Attempts to create the directory recursively (`mkdir -p` style) when absent. - Creates directories with mode 0755 so other users can read/list directory contents. - Performs final verification that the directory exists, is a directory, and writable. - Replaced the previous simple `access()` check in `nwipe.c` with the new directory-ensure logic. - Introduces clearer and more helpful error messages when directory creation or permission checks fail. Benefits: - Users can now safely specify custom report paths (e.g. `-P /reports` or USB-mounted paths) without requiring manual pre-creation. - Eliminates ambiguous error reporting and improves overall user experience. - Maintains backward-compatible behavior when the target directory already exists.