Skip to content

Commit

Permalink
stat.mode was wrong because I inverted logic on the readonly check
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Nov 12, 2015
1 parent 7b3acd2 commit 865df23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/jnr/posix/windows/CommonFileInformation.java
Expand Up @@ -49,7 +49,10 @@ public int getMode(java.lang.String path) {
int attr = getFileAttributes();
int mode = S_IRUSR;

if ((attr & FILE_ATTRIBUTE_READONLY) != 0) mode |= S_IWUSR;
if ((attr & FILE_ATTRIBUTE_READONLY) == 0) {
mode |= S_IWUSR;

}
mode |= (attr & FILE_ATTRIBUTE_DIRECTORY) != 0 ? (S_IFDIR | S_IXUSR) : S_IFREG;

path = path.toLowerCase();
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/jnr/posix/windows/WindowsFileTest.java
Expand Up @@ -3,6 +3,7 @@
import java.io.File;;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.NumberFormat;
import jnr.posix.DummyPOSIXHandler;
import jnr.posix.FileStat;
import jnr.posix.POSIX;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void testExecutableSuffixesAreExecutable() throws Throwable {

try {
FileStat st = posix.stat(f.getAbsolutePath());
assertEquals("100755", Integer.toOctalString(st.mode()));
assertTrue(st.isExecutable());
} finally {
f.delete();
Expand All @@ -100,6 +102,7 @@ public void testExecutableSuffixesAreExecutable() throws Throwable {

try {
FileStat st = posix.stat(f.getAbsolutePath());
assertEquals("100755", Integer.toOctalString(st.mode()));
assertTrue(st.isExecutable());
} finally {
f.delete();
Expand Down

0 comments on commit 865df23

Please sign in to comment.