mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 203240 - Permission of .cproject file seems not to be considered anywhere on writing data
This commit is contained in:
parent
9b091e5b66
commit
1c91522f2d
2 changed files with 62 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Broadcom Corporation and others.
|
* Copyright (c) 2008, 2011 Broadcom Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -41,6 +41,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testsuite for the project description storage. This
|
* Testsuite for the project description storage. This
|
||||||
|
@ -242,6 +243,8 @@ public class CProjectDescriptionStorageTests extends BaseTestCase {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testReadOnlyProjectDescription() throws Exception {
|
public void testReadOnlyProjectDescription() throws Exception {
|
||||||
|
enableSetWritableWhenHeadless(true);
|
||||||
|
try {
|
||||||
makeDescriptionReadOnly();
|
makeDescriptionReadOnly();
|
||||||
IProject project = cProj.getProject();
|
IProject project = cProj.getProject();
|
||||||
ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, true);
|
ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, true);
|
||||||
|
@ -263,6 +266,9 @@ public class CProjectDescriptionStorageTests extends BaseTestCase {
|
||||||
|
|
||||||
projDesc = CoreModel.getDefault().getProjectDescription(project, false);
|
projDesc = CoreModel.getDefault().getProjectDescription(project, false);
|
||||||
assertNull(projDesc.getDefaultSettingConfiguration().getStorage("Temp_testing_storage", false));
|
assertNull(projDesc.getDefaultSettingConfiguration().getStorage("Temp_testing_storage", false));
|
||||||
|
} finally {
|
||||||
|
enableSetWritableWhenHeadless(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -271,6 +277,14 @@ public class CProjectDescriptionStorageTests extends BaseTestCase {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables/disables team UI preference whether validateEdit should
|
||||||
|
* set files writable if no UI context has been provided.
|
||||||
|
*/
|
||||||
|
private void enableSetWritableWhenHeadless(boolean enable) {
|
||||||
|
InstanceScope.INSTANCE.getNode("org.eclipse.team.ui").putBoolean("org.eclipse.team.ui.validate_edit_with_no_context", enable);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* makes the project description (as stored by the XmlProjectDescriptionStorage &
|
* makes the project description (as stored by the XmlProjectDescriptionStorage &
|
||||||
* XmlProjectDescriptionStorage2) read-only. Does this using java.io.File deliberately.
|
* XmlProjectDescriptionStorage2) read-only. Does this using java.io.File deliberately.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Broadcom Corporation and others.
|
* Copyright (c) 2008, 2011 Broadcom Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -16,6 +16,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -44,16 +45,17 @@ import org.eclipse.cdt.internal.core.settings.model.xml2.XmlProjectDescriptionSt
|
||||||
import org.eclipse.core.filesystem.EFS;
|
import org.eclipse.core.filesystem.EFS;
|
||||||
import org.eclipse.core.filesystem.IFileInfo;
|
import org.eclipse.core.filesystem.IFileInfo;
|
||||||
import org.eclipse.core.filesystem.IFileStore;
|
import org.eclipse.core.filesystem.IFileStore;
|
||||||
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceVisitor;
|
|
||||||
import org.eclipse.core.resources.ResourceAttributes;
|
import org.eclipse.core.resources.ResourceAttributes;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.osgi.framework.Version;
|
import org.osgi.framework.Version;
|
||||||
|
@ -373,7 +375,7 @@ public class CProjectDescriptionStorageManager {
|
||||||
* Helper method to ensure that a resource is writable. This means: <br/>
|
* Helper method to ensure that a resource is writable. This means: <br/>
|
||||||
* - If the resource doesn't exist, it can be created (its parent is made writable) <br/>
|
* - If the resource doesn't exist, it can be created (its parent is made writable) <br/>
|
||||||
* - If the resource exists and its a file, it's made writable <br/>
|
* - If the resource exists and its a file, it's made writable <br/>
|
||||||
* - If the resource exists and its a directory, it and its children
|
* - If the resource exists and its a directory, it and its (direct) children
|
||||||
* are made writable
|
* are made writable
|
||||||
* @param resource
|
* @param resource
|
||||||
* @throws CoreException on failure
|
* @throws CoreException on failure
|
||||||
|
@ -390,16 +392,32 @@ public class CProjectDescriptionStorageManager {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If resource exists, ensure it and children are writable
|
// If resource exists, ensure it and children are writable
|
||||||
resource.accept(new IResourceVisitor() {
|
if (resource instanceof IFile) {
|
||||||
public boolean visit(IResource resource) throws CoreException {
|
if (resource.getResourceAttributes().isReadOnly()) {
|
||||||
|
IStatus result = resource.getWorkspace().validateEdit(new IFile[] { (IFile) resource }, null);
|
||||||
|
if (!result.isOK())
|
||||||
|
throw new CoreException(result);
|
||||||
|
}
|
||||||
|
} else if (resource instanceof IContainer) {
|
||||||
ResourceAttributes resAttr = resource.getResourceAttributes();
|
ResourceAttributes resAttr = resource.getResourceAttributes();
|
||||||
if (resAttr.isReadOnly()) {
|
if (resAttr.isReadOnly()) {
|
||||||
resAttr.setReadOnly(false);
|
resAttr.setReadOnly(false);
|
||||||
resource.setResourceAttributes(resAttr);
|
resource.setResourceAttributes(resAttr);
|
||||||
}
|
}
|
||||||
return true;
|
IResource[] members = ((IContainer) resource).members();
|
||||||
|
List<IFile> files = new ArrayList<IFile>(members.length);
|
||||||
|
for (IResource member : members) {
|
||||||
|
if (member instanceof IFile && member.getResourceAttributes().isReadOnly()) {
|
||||||
|
files.add((IFile) member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (files.size() > 0) {
|
||||||
|
IFile[] filesToValidate = files.toArray(new IFile[files.size()]);
|
||||||
|
IStatus result = resource.getWorkspace().validateEdit(filesToValidate, null);
|
||||||
|
if (!result.isOK())
|
||||||
|
throw new CoreException(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue