mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] ignoring DOS read-only attribute for directories (IDEA-117126)
This commit is contained in:
@@ -266,7 +266,7 @@ public class FileSystemUtil {
|
||||
long lastModified = (Long)myToMillis.invoke(attributes.get("lastModifiedTime"));
|
||||
if (SystemInfo.isWindows) {
|
||||
boolean isHidden = new File(path).getParent() == null ? false : (Boolean)attributes.get("hidden");
|
||||
boolean isWritable = !(Boolean)attributes.get("readonly");
|
||||
boolean isWritable = isDirectory || !(Boolean)attributes.get("readonly");
|
||||
return new FileAttributes(isDirectory, isOther, isSymbolicLink, isHidden, size, lastModified, isWritable);
|
||||
}
|
||||
else {
|
||||
@@ -546,19 +546,19 @@ public class FileSystemUtil {
|
||||
if (myFileSystem != null) {
|
||||
final int flags = (Integer)myGetBooleanAttributes.invoke(myFileSystem, file);
|
||||
if (flags != 0) {
|
||||
final boolean isDirectory = isSet(flags, BA_DIRECTORY);
|
||||
final boolean isSpecial = notSet(flags, BA_REGULAR | BA_DIRECTORY);
|
||||
final boolean isHidden = isSet(flags, BA_HIDDEN);
|
||||
return new FileAttributes(isDirectory, isSpecial, false, isHidden, file.length(), file.lastModified(), file.canWrite());
|
||||
boolean isDirectory = isSet(flags, BA_DIRECTORY);
|
||||
boolean isSpecial = notSet(flags, BA_REGULAR | BA_DIRECTORY);
|
||||
boolean isHidden = isSet(flags, BA_HIDDEN);
|
||||
boolean isWritable = SystemInfo.isWindows && isDirectory || file.canWrite();
|
||||
return new FileAttributes(isDirectory, isSpecial, false, isHidden, file.length(), file.lastModified(), isWritable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (file.exists()) {
|
||||
final boolean isDirectory = file.isDirectory();
|
||||
final boolean isSpecial = !isDirectory && !file.isFile();
|
||||
final boolean isHidden = file.isHidden();
|
||||
return new FileAttributes(isDirectory, isSpecial, false, isHidden, file.length(), file.lastModified(), file.canWrite());
|
||||
}
|
||||
else if (file.exists()) {
|
||||
boolean isDirectory = file.isDirectory();
|
||||
boolean isSpecial = !isDirectory && !file.isFile();
|
||||
boolean isHidden = file.isHidden();
|
||||
boolean isWritable = SystemInfo.isWindows && isDirectory || file.canWrite();
|
||||
return new FileAttributes(isDirectory, isSpecial, false, isHidden, file.length(), file.lastModified(), isWritable);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,8 +52,8 @@ public class FileInfo {
|
||||
final boolean isSymlink = isSet(attributes, FILE_ATTRIBUTE_REPARSE_POINT);
|
||||
final boolean isHidden = isSet(attributes, FILE_ATTRIBUTE_HIDDEN);
|
||||
final boolean isWritable = !isSet(attributes, FILE_ATTRIBUTE_READONLY);
|
||||
final long javaTimestamp = timestamp / 10000 - 11644473600000l;
|
||||
return new FileAttributes(isDirectory, isSpecial, isSymlink, isHidden, length, javaTimestamp, isWritable);
|
||||
final long javaTimestamp = timestamp / 10000 - 11644473600000L;
|
||||
return new FileAttributes(isDirectory, isSpecial, isSymlink, isHidden, length, javaTimestamp, isDirectory || isWritable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,6 +80,18 @@ public class FileAttributesReadingTest {
|
||||
assertEquals(file.getPath(), target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOnlyFile() throws Exception {
|
||||
final File file = FileUtil.createTempFile(myTempDirectory, "test.", ".txt");
|
||||
|
||||
String[] cmd = SystemInfo.isWindows ? new String[]{"attrib", "+R", file.getPath()} : new String[]{"chmod", "500", file.getPath()};
|
||||
assertEquals(0, Runtime.getRuntime().exec(cmd).waitFor());
|
||||
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
assertEquals(FileAttributes.Type.FILE, attributes.type);
|
||||
assertFalse(attributes.isWritable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directory() throws Exception {
|
||||
final File file = FileUtil.createTempDirectory(myTempDirectory, "test.", ".tmp");
|
||||
@@ -98,6 +110,18 @@ public class FileAttributesReadingTest {
|
||||
assertEquals(file.getPath(), target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOnlyDirectory() throws Exception {
|
||||
File file = FileUtil.createTempDirectory(myTempDirectory, "test.", ".tmp");
|
||||
|
||||
String[] cmd = SystemInfo.isWindows ? new String[]{"attrib", "+R", file.getPath()} : new String[]{"chmod", "500", file.getPath()};
|
||||
assertEquals(0, Runtime.getRuntime().exec(cmd).waitFor());
|
||||
|
||||
FileAttributes attributes = getAttributes(file);
|
||||
assertEquals(FileAttributes.Type.DIRECTORY, attributes.type);
|
||||
assertEquals(SystemInfo.isWindows, attributes.isWritable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void root() throws Exception {
|
||||
final File file = new File(SystemInfo.isWindows ? "C:\\" : "/");
|
||||
|
||||
Reference in New Issue
Block a user