common-workflow-language / common-workflow-language/cwltool

cwltool accidentally overwrites the contents of the file with `writable: false`

Open
#1,731 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
376
Forks
255
Avg merge
2d 7h
Merged PRs (30d)
12

Description

The [spec of Dirent#writable](https://www.commonwl.org/v1.2/CommandLineTool.html#Dirent) says:
> Default false (files and directories read-only by default).

Therefore I expect that the file with `writable: false` must not be overwritten by the tool but it can in actual.

## How to reproduce

```console
$ tree
.
└── cwl
└── notInplace.cwl

1 directory, 1 file
$ touch aaa.txt
$ cwltool cwl/notInplace.cwl --file=aaa.txt
```

## Expected Behavior
`cwltool` fails because the tool tries to write `bbb.txt` that is marked as `writable: false`.

## Actual Behavior
It accidentally succeeds its execution and the contents of `bbb.txt` and `aaa.txt` are overwritten.

```console
$ cwltool cwl/notInplace.cwl --file=aaa.txt
INFO /opt/homebrew/bin/cwltool 3.1.20220830195442
INFO Resolved 'cwl/notInplace.cwl' to 'file:///Users/tanjo/tmp/inplace/cwl/notInplace.cwl'
INFO [job notInplace.cwl] /private/tmp/docker_tmpgsoz_wey$ echo \
foobar > /private/tmp/docker_tmpgsoz_wey/bbb.txt
INFO [job notInplace.cwl] completed success
{
"out": {
"location": "file:///Users/tanjo/tmp/inplace/bbb.txt",
"basename": "bbb.txt",
"class": "File",
"checksum": "sha1$988881adc9fc3655077dc2d4d757d480b5ea0e11",
"size": 7,
"path": "/Users/tanjo/tmp/inplace/bbb.txt"
}
}
INFO Final process status is success
$ cat aaa.txt
foobar
$ cat bbb.txt
foobar
```

## Workflow Code
cwl/notInplace.cwl:
```cwl
cwlVersion: v1.2
class: CommandLineTool

requirements:
InitialWorkDirRequirement:
listing:
- entry: $(inputs.file)
entryname: bbb.txt
writable: false

baseCommand: echo
arguments: [ foobar ]
inputs:
- id: file
type: File
outputs:
out: stdout

stdout: bbb.txt
```

## Full Traceback
No exceptions.

## Your Environment
* cwltool version:
```console
$ cwltool --version
/opt/homebrew/bin/cwltool 3.1.20220830195442
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.