Skip to content

mustBeWritable = true does not work as expected for non-existing directories #579

Description

@sschuberth

I'm using code like

val outputDirectory by option()
    .file(mustExist = false, canBeFile = false, canBeDir = true, mustBeWritable = true, mustBeReadable = false, canBeSymlink = true)

This fails with

Error: invalid value for --output-directory: directory "/foo/bar" is not writable.

if there is no "bar" directory inside the existing (and writable) "foo" directory. This is problematic as the code in run() does not even get a chance to create the directory as the option validation is done before run() is called.

At least on the JVM, the cause seems to be the use of Files.isWritable at

if (mustBeWritable && !Files.isWritable(it)) fail(

which is documented to "check[s] that a file exists and that this Java virtual machine has appropriate privileges [...]". But actually, for a non-existing directory, it would be enough for the (closest existing) parent directory to be writable, so that the actual output directory can be created.

Activity

  1. xchacha20-poly1305 commented on Aug 10, 2026

    @xchacha20-poly1305

    What if add a option like createIfNotExisted?

  2. sschuberth commented on Aug 10, 2026

    @sschuberth
    ContributorAuthor

    IMO there should be no need to explicitly add such an option, but any missing directory should just be created for writable directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions