1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 23:25:26 +02:00

implemented new API IFileService.setReadOnly()

This commit is contained in:
Javier Montalvo Orus 2007-02-01 10:58:44 +00:00
parent 3cbe4296a7
commit d847b06501
3 changed files with 76 additions and 6 deletions

View file

@ -51,6 +51,7 @@ public class Activator extends Plugin {
/**
* Returns the shared instance.
* @return activator
*/
public static Activator getDefault() {
return plugin;

View file

@ -41,6 +41,7 @@ public class FTPHostFile implements IHostFile
private boolean _canWrite = true;
private boolean _isRoot;
private boolean _exists;
private FTPFile _ftpFile;
public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size, boolean exists)
{
@ -59,6 +60,7 @@ public class FTPHostFile implements IHostFile
public FTPHostFile(String parentPath, FTPFile ftpFile, String systemName)
{
_parentPath = parentPath;
_ftpFile = ftpFile;
if(systemName.equals(FTPClientConfig.SYST_VMS))
{
@ -184,6 +186,39 @@ public class FTPHostFile implements IHostFile
_isArchive = internalIsArchive();
}
public int getUserPermissions()
{
//user
int userRead = _ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) || _canRead ? 1 : 0;
int userWrite = _ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) || _canWrite ? 1 : 0;
int userExec = _ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0;
return userRead << 2 | userWrite << 1 | userExec;
}
public int getGroupPermissions()
{
//group
int groupRead = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? 1 : 0;
int groupWrite = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0;
int groupExec = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0;
return groupRead << 2 | groupWrite << 1 | groupExec;
}
public int getOtherPermissions()
{
//other
int otherRead = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? 1 : 0;
int otherWrite = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0;
int otherExec = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0;
return otherRead << 2 | otherWrite << 1 | otherExec;
}
protected boolean internalIsArchive()
{
return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath()))

View file

@ -418,7 +418,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
{
char separator = '/';
if(_systemName.equals(FTPClientConfig.SYST_NT) || _userHome.indexOf('\\')!=-1)
if((_systemName.equals(FTPClientConfig.SYST_NT) || _userHome.indexOf('\\')!=-1) && _userHome.indexOf('/')==-1)
{
separator = '\\';
}
@ -980,19 +980,53 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.files.IFileService#setLastModified(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, long)
*/
public boolean setLastModified(IProgressMonitor monitor, String parent,
String name, long timestamp) throws SystemMessageException
{
// TODO - implement this to set the timestamp
// not applicable for FTP
return false;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.files.IFileService#setReadOnly(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, boolean)
*/
public boolean setReadOnly(IProgressMonitor monitor, String parent,
String name, boolean readOnly) throws SystemMessageException {
// TODO Auto-generated method stub
return false;
boolean result = false;
int permissions = 0;
FTPHostFile file = (FTPHostFile)getFile(monitor,parent, name);
int userPermissions = file.getUserPermissions();
int groupPermissions = file.getGroupPermissions();
int otherPermissions = file.getOtherPermissions();
if(readOnly)
{
userPermissions &= 5; // & 101b
}
else
{
userPermissions |= 2; // | 010b
}
permissions = userPermissions * 100 + groupPermissions * 10 + otherPermissions;
try {
result =_ftpClient.sendSiteCommand("CHMOD "+permissions+" "+file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
result = false;
}
return result;
}
}
}