Repository: common-workflow-language/cwltool

Issue:
InputWorkDirRequirement error with Directories
## Expected Behavior
The directory in the `Dirent` should be created in the workdir for docker-based executions.

## Actual Behavior
It seems to work ok with run locally (not in container); however, some invalid field records are output to the logs (see traceback). When running within a container, there is an `OSError` because cwltool seems to try and make the `/var/spool/cwl` workdir locally.

## Workflow Code
```
cwlVersion: v1.0

class: CommandLineTool

requirements:
  - class: InlineJavascriptRequirement
  - class: InitialWorkDirRequirement
    listing:
      - entry: |
          ${
             return {"class": "Directory", "basename": inputs.out_dir, "listing": []}
           }
        writable: true

hints:
  - class: DockerRequirement
    dockerPull: alpine

inputs:
  out_dir:
    type: string?
    default: "out"

outputs:
  staged_dir:
    type: Directory
    outputBinding:
      glob: $(inputs.out_dir)

baseCommand: "true"
```

## Full Traceback

When running with docker image:

```pytb
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/cwltool/local/lib/python2.7/site-packages/cwltool/main.py", line 298, in single_job_executor
    r.run(**kwargs)
  File "/home/ubuntu/.virtualenvs/cwltool/local/lib/python2.7/site-packages/cwltool/job.py", line 427, in run
    self.add_volumes(self.generatemapper, runtime)
  File "/home/ubuntu/.virtualenvs/cwltool/local/lib/python2.7/site-packages/cwltool/job.py", line 344, in add_volumes
    os.makedirs(vol.target, 0o0755)
  File "/home/ubuntu/.virtualenvs/cwltool/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/ubuntu/.virtualenvs/cwltool/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/spool/cwl'
Workflow error, try again with --debug for more information:
[Errno 13] Permission denied: '/var/spool/cwl'
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/cwltool/local/lib/python2.7/site-packages/cwltool/main.py", line 976, in main
    **vars(args))
  File "/home/ubuntu/.virtualenvs/cwltool/local/lib/python2.7/site-packages/cwltool/main.py", line 306, in single_job_executor
    raise WorkflowException(Text(e))
WorkflowException: [Errno 13] Permission denied: '/var/spool/cwl'
```

While running with `--no-container`:

```
invalid field `nameext`, expected one of: 'class', 'location', 'path', 'basename', 'listing'
invalid field `nameroot`, expected one of: 'class', 'location', 'path', 'basename', 'listing'
[job error.cwl] completed success
[job error.cwl] {
    "staged_dir": {
        "basename": "out",
        "nameext": "",
        "nameroot": "out",
        "location": "file:///mnt/tmp/tmpgvqeFT/out",
        "class": "Directory"
    }
}
```

## Your Environment
* cwltool version: `1.0.20180116213856`

Edit: also saw this on `1.0.20171017195544` version

Edit2: it seems to work on `cwltool==1.0.20170723124118`


Discussion:

Resolving patch:
diff --git a/cwltool/job.py b/cwltool/job.py
--- a/cwltool/job.py
+++ b/cwltool/job.py
@@ -341,7 +341,7 @@ def add_volumes(self, pathmapper, runtime):
                     ensure_writable(host_outdir_tgt)
             elif vol.type == "WritableDirectory":
                 if vol.resolved.startswith("_:"):
-                    os.makedirs(vol.target, 0o0755)
+                    os.makedirs(host_outdir_tgt, 0o0755)
                 else:
                     if self.inplace_update:
                         runtime.append(u"--volume=%s:%s:rw" % (


Test patch: