Details
Description
The call to "attrib" to make directories read-only on windows in jstests/readonly/libs/read_only_test.js always fails in the read_only, read_only_WT, read_only_sharded, and read_only_sharded_WT tasks on Windows 2008R2 DEBUG.
Here is one example from a recent commit:
This is because the use of "attrib" on the following lines is incorrect:
- https://github.com/mongodb/mongo/blob/r3.4.0-rc0/jstests/readonly/lib/read_only_test.js#L8
- https://github.com/mongodb/mongo/blob/r3.4.0-rc0/jstests/readonly/lib/read_only_test.js#L16
This use of "attrib" fails even directly on the command line on Windows 2008R2:
$ mkdir testdir |
$ ls -oh |
drwxrwxr-x+ 1 Administrator 0 Oct 18 21:50 testdir
|
$ attrib +r testdir /s |
File not found - testdir <-------------
|
A minimal fix is to instead do "attrib +r <dir>/*.* /s"
$ mkdir testdir |
# Create a regular file, subdirectory, and regular file in the subdirectory
|
$ touch testdir/foo |
$ mkdir testdir/subdir |
$ touch testdir/subdir/subfoo |
# Make all *regular* files in the base directory read-only
|
$ attrib +r testdir/*.* /s |
$ echo "bar" > testdir/foo |
-bash: testdir/foo: Permission denied |
$ echo "bar" > testdir/subdir/subfoo |
-bash: testdir/subdir/subfoo: Permission denied |
Note that if the directory does not contain any regular files, this "attrib" command will fail:
$ mkdir testdir |
# No files were added to testdir
|
$ attrib +r testdir/*.* /s |
File not found - testdir/*.*
|
Also note that new files, new subdirectories, and new files in those new subdirectories can still be created even after making all existing regular files in the directory read-only:
$ mkdir testdir |
$ touch testdir/foo |
$ attrib +r testdir/*.* /s |
# New regular file "foo2" can be created
|
$ touch testdir/foo2 |
$ ls testdir |
foo foo2
|
# New subdirectory "subdir" can be created
|
$ mkdir testdir/subdir |
$ ls testdir |
foo foo2 subdir
|
# New regular file "subfoo" in the new subdirectory can be created
|
$ touch testdir/subdir/subfoo |
$ ls testdir/subdir |
subfoo
|