@Override
    public void preflight(final Path workdir, final String filename) throws BackgroundException {
        if(!validate(filename)) {
            throw new InvalidFilenameException(MessageFormat.format(LocaleFactory.localizedString("Cannot create {0}", "Error"), filename));
        }

        // File/directory creation summary:
        // - Directories with ctera:writepermission but no ctera:createdirectoriespermission allow for file creation only.
        // - Directories with ctera:createdirectoriespermission but no ctera:writepermission allow for directory and file creation.
        // - Directories with only ctera:readpermission do not allow for file nor directory creation, for listing only.
        // In other words:
        // - file creation is allowed if either ctera:createdirectoriespermission or ctera:writepermission is set or both are set
        // - directory creation is allowed if ctera:createdirectoriespermission is set.

        // ctera:createdirectoriespermission or ctera:writepermission
        try {
            assumeRole(workdir, WRITEPERMISSION);
        }
        catch(AccessDeniedException e) {
            // ignore and try second option
            assumeRole(workdir, CREATEDIRECTORIESPERMISSION);
        }
    }
@Test
    public void testPreflightWriteAndCreateDirectoriesPermission() throws Exception {
        final Path file = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
        file.setAttributes(file.attributes().withAcl(
                new Acl(
                        new Acl.UserAndRole(new Acl.CanonicalUser(), WRITEPERMISSION),
                        new Acl.UserAndRole(new Acl.CanonicalUser(), CREATEDIRECTORIESPERMISSION)
                )));
        new CteraTouchFeature(session).preflight(file, new AlphanumericRandomStringService().random());
        // assert no fail
    }