mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[updater] skips write-ability check for delete actions
This commit is contained in:
@@ -103,10 +103,10 @@ public abstract class BaseUpdateAction extends PatchAction {
|
||||
@Override
|
||||
public ValidationResult validate(File toDir) throws IOException {
|
||||
File fromFile = getSource(toDir);
|
||||
ValidationResult result = doValidateAccess(fromFile, ValidationResult.Action.UPDATE);
|
||||
ValidationResult result = doValidateAccess(fromFile, ValidationResult.Action.UPDATE, true);
|
||||
if (result != null) return result;
|
||||
if (!mySource.isEmpty()) {
|
||||
result = doValidateAccess(getFile(toDir), ValidationResult.Action.UPDATE);
|
||||
result = doValidateAccess(getFile(toDir), ValidationResult.Action.UPDATE, true);
|
||||
if (result != null) return result;
|
||||
}
|
||||
return doValidateNotChanged(fromFile, ValidationResult.Kind.ERROR, ValidationResult.Action.UPDATE);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CreateAction extends PatchAction {
|
||||
@Override
|
||||
public ValidationResult validate(File toDir) {
|
||||
File toFile = getFile(toDir);
|
||||
ValidationResult result = doValidateAccess(toFile, ValidationResult.Action.CREATE);
|
||||
ValidationResult result = doValidateAccess(toFile, ValidationResult.Action.CREATE, true);
|
||||
if (result != null) return result;
|
||||
|
||||
if (toFile.exists()) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DeleteAction extends PatchAction {
|
||||
@Override
|
||||
public ValidationResult validate(File toDir) throws IOException {
|
||||
File toFile = getFile(toDir);
|
||||
ValidationResult result = doValidateAccess(toFile, ValidationResult.Action.DELETE);
|
||||
ValidationResult result = doValidateAccess(toFile, ValidationResult.Action.DELETE, false);
|
||||
if (result != null) return result;
|
||||
|
||||
if (myPatch.validateDeletion(getPath()) && toFile.exists() && isModified(toFile)) {
|
||||
|
||||
@@ -135,10 +135,11 @@ public abstract class PatchAction {
|
||||
|
||||
protected abstract ValidationResult validate(File toDir) throws IOException;
|
||||
|
||||
protected ValidationResult doValidateAccess(File toFile, ValidationResult.Action action) {
|
||||
protected ValidationResult doValidateAccess(File toFile, ValidationResult.Action action, boolean checkWriteable) {
|
||||
if (!toFile.exists() || toFile.isDirectory()) return null;
|
||||
ValidationResult result = validateProcessLock(toFile, action);
|
||||
if (result != null) return result;
|
||||
if (!checkWriteable) return null;
|
||||
if (toFile.canRead() && toFile.canWrite() && isWritable(toFile)) return null;
|
||||
ValidationResult.Option[] options = {myPatch.isStrict() ? ValidationResult.Option.NONE : ValidationResult.Option.IGNORE};
|
||||
return new ValidationResult(ValidationResult.Kind.ERROR, myPath, action, ValidationResult.ACCESS_DENIED_MESSAGE, options);
|
||||
|
||||
@@ -510,6 +510,18 @@ public abstract class PatchApplyingRevertingTest extends PatchTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadOnlyFilesAreDeletable() throws Exception {
|
||||
File file = new File(myOlderDir, "bin/read_only_to_delete");
|
||||
FileUtil.writeToFile(file, "bye");
|
||||
assertTrue(file.setWritable(false, false));
|
||||
|
||||
Patch patch = createPatch();
|
||||
PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI);
|
||||
assertThat(preparationResult.validationResults).isEmpty();
|
||||
assertAppliedAndRevertedCorrectly(patch, preparationResult);
|
||||
}
|
||||
|
||||
|
||||
protected PatchAction getAction(Patch patch, String path) {
|
||||
return ContainerUtil.find(patch.getActions(), a -> a.getPath().equals(path));
|
||||
|
||||
Reference in New Issue
Block a user