mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-23 00:03:53 +02:00
new API IFileService.setReadOnly()
This commit is contained in:
parent
141616a037
commit
74822bd918
11 changed files with 159 additions and 24 deletions
|
@ -19,6 +19,7 @@ import java.text.DateFormat;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.rse.model.ISystemResourceChangeEvents;
|
||||
import org.eclipse.rse.services.files.RemoteFileIOException;
|
||||
import org.eclipse.rse.services.files.RemoteFileSecurityException;
|
||||
|
@ -220,7 +221,7 @@ public class SystemFilePropertyPage extends SystemBasePropertyPage
|
|||
{
|
||||
cbReadonlyPrompt.setSelection(!file.canWrite());
|
||||
wasReadOnly = !file.canWrite();
|
||||
if (wasReadOnly || file instanceof IVirtualRemoteFile)
|
||||
if (file instanceof IVirtualRemoteFile)
|
||||
cbReadonlyPrompt.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
@ -252,11 +253,14 @@ public class SystemFilePropertyPage extends SystemBasePropertyPage
|
|||
public boolean performOk()
|
||||
{
|
||||
boolean ok = super.performOk();
|
||||
if (ok && (cbReadonlyPrompt!=null) && cbReadonlyPrompt.getSelection() && !wasReadOnly)
|
||||
boolean readOnlySelected = cbReadonlyPrompt != null ? cbReadonlyPrompt.getSelection() : false;
|
||||
if (ok && (cbReadonlyPrompt!=null) &&
|
||||
((readOnlySelected && !wasReadOnly) ||
|
||||
(!readOnlySelected && wasReadOnly)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getRemoteFile().getParentRemoteFileSubSystem().setReadOnly(getRemoteFile());
|
||||
getRemoteFile().getParentRemoteFileSubSystem().setReadOnly(new NullProgressMonitor(), getRemoteFile(), readOnlySelected);
|
||||
RSEUIPlugin.getTheSystemRegistry().fireEvent(
|
||||
new org.eclipse.rse.model.SystemResourceChangeEvent(
|
||||
getRemoteFile(),ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE,null));
|
||||
|
|
|
@ -1257,20 +1257,64 @@ private DataElement createDataElementFromLSString(DataElement subject,
|
|||
*/
|
||||
public DataElement handleSetReadOnly(DataElement subject, DataElement status) {
|
||||
|
||||
File filename = new File(subject.getAttribute(DE.A_VALUE)
|
||||
+ File.separatorChar + subject.getName());
|
||||
File filename = new File(subject.getAttribute(DE.A_VALUE), subject.getAttribute(DE.A_NAME));
|
||||
|
||||
if (!filename.exists())
|
||||
{
|
||||
filename = new File(subject.getAttribute(DE.A_VALUE));
|
||||
}
|
||||
if (!filename.exists())
|
||||
status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST);
|
||||
else {
|
||||
try {
|
||||
boolean done = filename.setReadOnly();
|
||||
if (done) {
|
||||
String str = subject.getAttribute(DE.A_SOURCE);
|
||||
boolean readOnly = false;
|
||||
if (str.equals("true")) //$NON-NLS-1$
|
||||
{
|
||||
readOnly = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
readOnly = false;
|
||||
}
|
||||
boolean done = false;
|
||||
if (readOnly)
|
||||
{
|
||||
done = filename.setReadOnly();
|
||||
}
|
||||
else
|
||||
{
|
||||
// doesn't handle non-unix
|
||||
if (!_isWindows)
|
||||
{
|
||||
// make this read-write
|
||||
String[] cmd = new String[3];
|
||||
cmd[0] = "chmod"; //$NON-NLS-1$
|
||||
cmd[1] = "a+w"; //$NON-NLS-1$
|
||||
cmd[2] = filename.getAbsolutePath();
|
||||
Process p = Runtime.getRuntime().exec(cmd);
|
||||
int exitValue = p.waitFor();
|
||||
done = (exitValue == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
if (done)
|
||||
{
|
||||
status.setAttribute(DE.A_SOURCE, SUCCESS);
|
||||
subject.setAttribute(DE.A_SOURCE, setProperties(filename));
|
||||
_dataStore.refresh(subject);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
status.setAttribute(DE.A_SOURCE, FAILED);
|
||||
}
|
||||
|
||||
// update filename?
|
||||
filename = new File(filename.getAbsolutePath());
|
||||
subject.setAttribute(DE.A_SOURCE, setProperties(filename));
|
||||
_dataStore.refresh(subject);
|
||||
|
||||
} catch (Exception e) {
|
||||
UniversalServerUtilities.logError(CLASSNAME,
|
||||
"handleSetreadOnly", e); //$NON-NLS-1$
|
||||
|
@ -1286,7 +1330,12 @@ private DataElement createDataElementFromLSString(DataElement subject,
|
|||
public DataElement handleSetLastModified(DataElement subject,
|
||||
DataElement status)
|
||||
{
|
||||
File filename = new File(subject.getAttribute(DE.A_VALUE));
|
||||
File filename = new File(subject.getAttribute(DE.A_VALUE), subject.getAttribute(DE.A_NAME));
|
||||
|
||||
if (!filename.exists())
|
||||
{
|
||||
filename = new File(subject.getAttribute(DE.A_VALUE));
|
||||
}
|
||||
if (!filename.exists())
|
||||
status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST);
|
||||
else {
|
||||
|
@ -1296,13 +1345,18 @@ private DataElement createDataElementFromLSString(DataElement subject,
|
|||
long date = Long.parseLong(str);
|
||||
boolean done = filename.setLastModified(date);
|
||||
|
||||
filename = new File(subject.getAttribute(DE.A_VALUE));
|
||||
if (done) {
|
||||
status.setAttribute(DE.A_SOURCE, SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
status.setAttribute(DE.A_SOURCE, FAILED);
|
||||
}
|
||||
|
||||
filename = new File(filename.getAbsolutePath());
|
||||
subject.setAttribute(DE.A_SOURCE, setProperties(filename));
|
||||
_dataStore.refresh(subject);
|
||||
} else
|
||||
status.setAttribute(DE.A_SOURCE, FAILED);
|
||||
|
||||
} catch (Exception e) {
|
||||
UniversalServerUtilities.logError(CLASSNAME,
|
||||
"handleSetLastModified", e); //$NON-NLS-1$
|
||||
|
|
|
@ -1238,8 +1238,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
|||
DataElement setCmd = getCommandDescriptor(de, C_SET_LASTMODIFIED);
|
||||
if (setCmd != null)
|
||||
{
|
||||
|
||||
|
||||
// first modify the source attribute to temporarily be the date field
|
||||
de.setAttribute(DE.A_SOURCE, timestamp + ""); //$NON-NLS-1$
|
||||
ds.command(setCmd, de, true);
|
||||
|
@ -1249,6 +1247,33 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setReadOnly(IProgressMonitor monitor, String parent,
|
||||
String name, boolean readOnly) throws SystemMessageException
|
||||
{
|
||||
String remotePath = parent + getSeparator(parent) + name;
|
||||
DataElement de = getElementFor(remotePath);
|
||||
DataStore ds = de.getDataStore();
|
||||
|
||||
|
||||
DataElement setCmd = getCommandDescriptor(de, C_SET_READONLY);
|
||||
if (setCmd != null)
|
||||
{
|
||||
String flag = readOnly ? "true" : "false";
|
||||
de.setAttribute(DE.A_SOURCE, flag);
|
||||
DataElement status = ds.command(setCmd, de, true);
|
||||
try
|
||||
{
|
||||
getStatusMonitor(ds).waitForUpdate(status);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -356,6 +356,10 @@ public class DStoreHostFile implements IHostFile
|
|||
|
||||
public boolean canRead() {
|
||||
String str = getAttribute(_element.getSource(), ATTRIBUTE_CAN_READ);
|
||||
if (str == null)
|
||||
{
|
||||
System.out.println("HELP:"+_element.toString());
|
||||
}
|
||||
return(str.equals("true")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
|
|
@ -988,5 +988,11 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setReadOnly(IProgressMonitor monitor, String parent,
|
||||
String name, boolean readOnly) throws SystemMessageException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1316,5 +1316,20 @@ public class LocalFileService extends AbstractFileService implements IFileServic
|
|||
return file.setLastModified(timestamp);
|
||||
}
|
||||
|
||||
public boolean setReadOnly(IProgressMonitor monitor, String parent,
|
||||
String name, boolean readOnly) throws SystemMessageException
|
||||
{
|
||||
File file = new File(parent, name);
|
||||
if (readOnly)
|
||||
{
|
||||
return file.setReadOnly();
|
||||
}
|
||||
else
|
||||
{
|
||||
// not implemented yet
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -759,4 +759,10 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setReadOnly(IProgressMonitor monitor, String parent,
|
||||
String name, boolean readOnly) throws SystemMessageException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -274,4 +274,14 @@ public interface IFileService extends IService
|
|||
* @return true if the file timestamp was changed successfully
|
||||
*/
|
||||
public boolean setLastModified(IProgressMonitor monitor, String parent, String name, long timestamp) throws SystemMessageException;
|
||||
|
||||
/**
|
||||
* Sets the readonly permission of the file or folder
|
||||
* @param monitor the progress monitor
|
||||
* @param parent the parent path of the file to set
|
||||
* @param name the name of the file to set
|
||||
* @param readOnly indicates whether to make the file readonly or read-write
|
||||
* @return true if the readonly permission was changed successfully
|
||||
*/
|
||||
public boolean setReadOnly(IProgressMonitor monitor, String parent, String name, boolean readOnly) throws SystemMessageException;
|
||||
}
|
|
@ -188,8 +188,7 @@ public abstract class AbstractRemoteFile extends RemoteFile implements IRemoteFi
|
|||
|
||||
public boolean showReadOnlyProperty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public IHostFile getHostFile()
|
||||
|
|
|
@ -778,11 +778,21 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
|
|||
}
|
||||
}
|
||||
|
||||
public boolean setReadOnly(IRemoteFile folderOrFile) throws RemoteFileSecurityException, RemoteFileIOException
|
||||
public boolean setReadOnly(IProgressMonitor monitor, IRemoteFile folderOrFile, boolean readOnly) throws RemoteFileSecurityException, RemoteFileIOException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
String name = folderOrFile.getName();
|
||||
String parent = folderOrFile.getParentPath();
|
||||
try
|
||||
{
|
||||
return _hostFileService.setReadOnly(monitor, parent, name, readOnly);
|
||||
}
|
||||
catch (SystemMessageException e)
|
||||
{
|
||||
SystemMessageDialog dlg = new SystemMessageDialog(getShell(), e.getSystemMessage());
|
||||
dlg.open();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ILanguageUtilityFactory getLanguageUtilityFactory()
|
||||
{
|
||||
|
|
|
@ -354,13 +354,15 @@ public interface IRemoteFileSubSystem extends ISubSystem{
|
|||
public boolean setLastModified(IProgressMonitor monitor, IRemoteFile folderOrFile, long newDate) throws RemoteFileSecurityException, RemoteFileIOException;
|
||||
|
||||
/**
|
||||
* Set a file to readonly.
|
||||
* Set a files readonly permissions.
|
||||
* Folder or file must exist on disk for this to succeed.
|
||||
*
|
||||
* @param monitor the progress monitor
|
||||
* @param folderOrFile represents the object to be renamed.
|
||||
* @param readOnly whether to set it to be readonly or not
|
||||
* @return false if the given folder/file didn't exist on disk (operation fails), else true. Throws an exception if anything fails.
|
||||
*/
|
||||
public boolean setReadOnly(IRemoteFile folderOrFile) throws RemoteFileSecurityException, RemoteFileIOException;
|
||||
public boolean setReadOnly(IProgressMonitor monitor, IRemoteFile folderOrFile, boolean readOnly) throws RemoteFileSecurityException, RemoteFileIOException;
|
||||
|
||||
|
||||
// ----------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue