View | Details | Raw Unified | Return to bug 209593 | Differences between
and this patch

Collapse All | Expand All

(-)miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java (+170 lines)
Lines 28-38 Link Here
28
 * David McKnight   (IBM)        - [196624] dstore miner IDs should be String constants rather than dynamic lookup
28
 * David McKnight   (IBM)        - [196624] dstore miner IDs should be String constants rather than dynamic lookup
29
 * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
29
 * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
30
 * Xuan Chen (IBM) - [194481] [dstore][Archive] Save Conflict After Renaming a File that is Open
30
 * Xuan Chen (IBM) - [194481] [dstore][Archive] Save Conflict After Renaming a File that is Open
31
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
31
 *******************************************************************************/
32
 *******************************************************************************/
32
33
33
package org.eclipse.rse.dstore.universal.miners;
34
package org.eclipse.rse.dstore.universal.miners;
35
import java.io.BufferedReader;
34
import java.io.File;
36
import java.io.File;
35
import java.io.IOException;
37
import java.io.IOException;
38
import java.io.InputStreamReader;
36
import java.net.ServerSocket;
39
import java.net.ServerSocket;
37
import java.util.HashMap;
40
import java.util.HashMap;
38
import java.util.Iterator;
41
import java.util.Iterator;
Lines 57-62 Link Here
57
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalSearchHandler;
60
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalSearchHandler;
58
import org.eclipse.rse.services.clientserver.IClientServerConstants;
61
import org.eclipse.rse.services.clientserver.IClientServerConstants;
59
import org.eclipse.rse.services.clientserver.IServiceConstants;
62
import org.eclipse.rse.services.clientserver.IServiceConstants;
63
import org.eclipse.rse.services.clientserver.PathUtility;
60
import org.eclipse.rse.services.clientserver.SystemFileClassifier;
64
import org.eclipse.rse.services.clientserver.SystemFileClassifier;
61
import org.eclipse.rse.services.clientserver.SystemSearchString;
65
import org.eclipse.rse.services.clientserver.SystemSearchString;
62
import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath;
66
import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath;
Lines 206-211 Link Here
206
				return handleQueryClassName(subject, status);
210
				return handleQueryClassName(subject, status);
207
		} else if (IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME.equals(name)) {
211
		} else if (IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME.equals(name)) {
208
				return handleQueryQualifiedClassName(subject, status);
212
				return handleQueryQualifiedClassName(subject, status);
213
		} else if (IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS.equals(name)) {
214
				return handleQueryFilePermissions(subject, status);
215
		} else if (IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS.equals(name)) {
216
				DataElement newPermissions = getCommandArgument(theElement, 1);
217
                return handleSetFilePermissions(subject, newPermissions, status);			
218
		} else if (IUniversalDataStoreConstants.C_QUERY_FILE_OWNER.equals(name)) {	
219
				return handleQueryFileOwner(subject, status);
220
		} else if (IUniversalDataStoreConstants.C_SET_FILE_OWNER.equals(name)) {
221
				DataElement newOwner = getCommandArgument(theElement, 1);
222
				return handleSetFileOwner(subject, newOwner, status);
209
		} else {
223
		} else {
210
			UniversalServerUtilities.logError(CLASSNAME,
224
			UniversalServerUtilities.logError(CLASSNAME,
211
					"Invalid query to handlecommand", null); //$NON-NLS-1$
225
					"Invalid query to handlecommand", null); //$NON-NLS-1$
Lines 1554-1560 Link Here
1554
		// command descriptor to retrieve qualified class name for class file
1568
		// command descriptor to retrieve qualified class name for class file
1555
		createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetFullClassName", //$NON-NLS-1$
1569
		createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetFullClassName", //$NON-NLS-1$
1556
				IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME);
1570
				IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME);
1571
		
1572
		
1573
		// permissions and ownership not supported on windows
1574
		if (!_isWindows) {
1575
			// descriptors for permissions
1576
			createCommandDescriptor(UniversalFilter, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1577
			createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1578
			createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1579
			createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "GetPermissions",IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1580
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFileObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1581
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFolderObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$
1582
	
1583
			createCommandDescriptor(UniversalFilter, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1584
			createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1585
			createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1586
			createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "SetPermissions",IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1587
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFileObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1588
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFolderObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$
1589
	
1590
			
1591
			// descriptors for ownership
1592
			createCommandDescriptor(UniversalFilter, "GetOwner", IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1593
			createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetOwner", IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1594
			createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetOwner", IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1595
			createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "GetOwner",IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1596
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFileObject, "GetOwner", IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1597
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFolderObject, "GetOwner", IUniversalDataStoreConstants.C_QUERY_FILE_OWNER); //$NON-NLS-1$
1598
		
1599
			createCommandDescriptor(UniversalFilter, "SetOwner", IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1600
			createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "SetOwner", IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1601
			createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetOwner", IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1602
			createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "SetOwner",IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1603
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFileObject, "SetOwner", IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1604
			createCommandDescriptor(FileDescriptors._deUniversalVirtualFolderObject, "SetOwner", IUniversalDataStoreConstants.C_SET_FILE_OWNER); //$NON-NLS-1$
1605
		}
1557
	}
1606
	}
1607
	
1558
1608
1559
	public AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) {
1609
	public AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) {
1560
		StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE));
1610
		StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE));
Lines 1706-1709 Link Here
1706
	{
1756
	{
1707
		return "7.0.0"; //$NON-NLS-1$
1757
		return "7.0.0"; //$NON-NLS-1$
1708
	}
1758
	}
1759
	
1760
	private File getFileFor(DataElement subject)
1761
	{
1762
		File fileobj = null;
1763
		boolean isVirtual = false;
1764
		boolean isFilter = false;
1765
		String fullName = subject.getValue();
1766
		String queryType = subject.getType();
1767
		if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) 
1768
		{
1769
			isFilter = true;
1770
			isVirtual = ArchiveHandlerManager.isVirtual(fullName);
1771
			String filterValue = subject.getValue();
1772
			// . translates to home dir
1773
			if (filterValue.equals("."))  //$NON-NLS-1$
1774
			{
1775
				filterValue = System.getProperty("user.home"); //$NON-NLS-1$
1776
				subject.setAttribute(DE.A_VALUE, filterValue);
1777
			}
1778
			if (!isVirtual)
1779
				fileobj = new File(filterValue);
1780
		} 
1781
		else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR))
1782
		{
1783
			String name = subject.getName();
1784
			String path = subject.getValue();
1785
			fileobj = new File(path, name);	
1786
		}
1787
		else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR))
1788
		{
1789
			String name = subject.getName();			
1790
			String path = subject.getValue();
1791
			if (name.length() == 0)
1792
			{
1793
				fileobj = new File(path);
1794
			}
1795
			else
1796
			{
1797
				fileobj = new File(path, name);		
1798
			}
1799
		}
1800
		else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR))
1801
		{
1802
			isVirtual = true;
1803
		}
1804
		return fileobj;
1805
	}
1806
	
1807
	
1808
	
1809
	private String simpleShellCommand(String cmd, File file)
1810
	{
1811
		String result = null;
1812
	    String args[] = new String[3];
1813
        args[0] = "sh"; //$NON-NLS-1$
1814
        args[1] = "-c"; //$NON-NLS-1$
1815
        args[2] = cmd + " " + PathUtility.enQuoteUnix(file.getAbsolutePath()); //$NON-NLS-1$
1816
     
1817
        BufferedReader childReader = null;
1818
		try {
1819
        	Process childProcess = Runtime.getRuntime().exec(args);
1820
        	
1821
        	childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream()));
1822
1823
        	result = childReader.readLine().trim();
1824
        	childReader.close();
1825
		}
1826
		catch (Exception e){
1827
			try {
1828
				childReader.close();
1829
			}
1830
			catch (IOException ex){}
1831
		}
1832
		return result;
1833
	        	
1834
	}
1835
	
1836
	private DataElement handleQueryFilePermissions(DataElement subject, DataElement status)
1837
	{
1838
		File file = getFileFor(subject);
1839
		String result = simpleShellCommand("stat -c%a", file); //$NON-NLS-1$
1840
		
1841
        status.setAttribute(DE.A_SOURCE, result);
1842
    	statusDone(status);
1843
	
1844
		return status;
1845
	}
1846
1847
	private DataElement handleSetFilePermissions(DataElement subject, DataElement newPermissions, DataElement status)
1848
	{
1849
		File file = getFileFor(subject);
1850
		String result = simpleShellCommand("chmod " + newPermissions, file); //$NON-NLS-1$
1851
		
1852
        status.setAttribute(DE.A_SOURCE, result);
1853
    	statusDone(status);
1854
	
1855
		return status;
1856
	}
1857
	
1858
	private DataElement handleQueryFileOwner(DataElement subject, DataElement status)
1859
	{
1860
		File file = getFileFor(subject);
1861
		String result = simpleShellCommand("stat -c%U", file); //$NON-NLS-1$
1862
		
1863
        status.setAttribute(DE.A_SOURCE, result);
1864
    	statusDone(status);
1865
	
1866
		return status;
1867
	}
1868
	
1869
	private DataElement handleSetFileOwner(DataElement subject, DataElement newOwner, DataElement status)
1870
	{
1871
		File file = getFileFor(subject);
1872
		String result = simpleShellCommand("chown " + newOwner.getName(), file); //$NON-NLS-1$
1873
		
1874
        status.setAttribute(DE.A_SOURCE, result);
1875
    	statusDone(status);
1876
		return status;
1877
	}
1878
	
1709
}
1879
}
(-)miners/org/eclipse/rse/dstore/universal/miners/IUniversalDataStoreConstants.java (-2 / +8 lines)
Lines 96-103 Link Here
96
	public static final String C_QUERY_QUALIFIED_CLASSNAME = "C_QUERY_QUALIFIED_CLASSNAME"; //$NON-NLS-1$
96
	public static final String C_QUERY_QUALIFIED_CLASSNAME = "C_QUERY_QUALIFIED_CLASSNAME"; //$NON-NLS-1$
97
	public static final String TYPE_QUALIFIED_CLASSNAME = "fullClassName"; //$NON-NLS-1$
97
	public static final String TYPE_QUALIFIED_CLASSNAME = "fullClassName"; //$NON-NLS-1$
98
	
98
	
99
99
	// permissions commands
100
    	
100
	public static final String C_QUERY_FILE_PERMISSIONS = "C_QUERY_FILE_PERMISSIONS";
101
	public static final String C_SET_FILE_PERMISSIONS = "C_SET_FILE_PERMISSIONS";
102
	
103
	// ownership command
104
    public static final String C_QUERY_FILE_OWNER = "C_QUERY_FILE_OWNER";	
105
    public static final String C_SET_FILE_OWNER = "C_SET_FILE_OWNER";
106
	
101
	// Mode of transfer: text or binary
107
	// Mode of transfer: text or binary
102
	public static final int TEXT_MODE = -1;
108
	public static final int TEXT_MODE = -1;
103
	public static final int BINARY_MODE = -2;
109
	public static final int BINARY_MODE = -2;
(-)src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java (-3 / +136 lines)
Lines 31-37 Link Here
31
 * Kevin Doyle		(IBM)		 - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
31
 * Kevin Doyle		(IBM)		 - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
32
 * David McKnight   (IBM)        - [196624] dstore miner IDs should be String constants rather than dynamic lookup
32
 * David McKnight   (IBM)        - [196624] dstore miner IDs should be String constants rather than dynamic lookup
33
 * David McKnight   (IBM)        - [209704] added supportsEncodingConversion()
33
 * David McKnight   (IBM)        - [209704] added supportsEncodingConversion()
34
 * Xuan Chen        (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
34
 * Xuan Chen        (IBM)        - [209827] Update DStore command implementation to enable cancelation of archive operations
35
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
35
 ********************************************************************************/
36
 ********************************************************************************/
36
37
37
package org.eclipse.rse.internal.services.dstore.files;
38
package org.eclipse.rse.internal.services.dstore.files;
Lines 74-85 Link Here
74
import org.eclipse.rse.services.dstore.util.DownloadListener;
75
import org.eclipse.rse.services.dstore.util.DownloadListener;
75
import org.eclipse.rse.services.dstore.util.FileSystemMessageUtil;
76
import org.eclipse.rse.services.dstore.util.FileSystemMessageUtil;
76
import org.eclipse.rse.services.files.CodePageConverterManager;
77
import org.eclipse.rse.services.files.CodePageConverterManager;
78
import org.eclipse.rse.services.files.HostFilePermissions;
79
import org.eclipse.rse.services.files.IFileOwnerService;
80
import org.eclipse.rse.services.files.IFilePermissionsService;
77
import org.eclipse.rse.services.files.IFileService;
81
import org.eclipse.rse.services.files.IFileService;
78
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
82
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
79
import org.eclipse.rse.services.files.IHostFile;
83
import org.eclipse.rse.services.files.IHostFile;
84
import org.eclipse.rse.services.files.IHostFilePermissions;
80
import org.eclipse.rse.services.files.RemoteFileSecurityException;
85
import org.eclipse.rse.services.files.RemoteFileSecurityException;
81
86
82
public class DStoreFileService extends AbstractDStoreService implements IFileService
87
public class DStoreFileService extends AbstractDStoreService implements IFileService, IFilePermissionsService, IFileOwnerService
83
{
88
{
84
89
85
	protected org.eclipse.dstore.core.model.DataElement _uploadLogElement = null;
90
	protected org.eclipse.dstore.core.model.DataElement _uploadLogElement = null;
Lines 1217-1223 Link Here
1217
		}						
1222
		}						
1218
		else
1223
		else
1219
		{
1224
		{
1220
			file = new DStoreHostFile(element);
1225
			file = new DStoreHostFile(element);	
1221
		}
1226
		}
1222
		String path =  file.getAbsolutePath();
1227
		String path =  file.getAbsolutePath();
1223
		_fileElementMap.put(path, element);
1228
		_fileElementMap.put(path, element);
Lines 2067-2070 Link Here
2067
	public boolean supportsEncodingConversion(){
2072
	public boolean supportsEncodingConversion(){
2068
		return true;
2073
		return true;
2069
	}
2074
	}
2075
2076
	
2077
	
2078
	
2079
	public boolean canGetFilePermissions(String remoteParent, String name) {
2080
		
2081
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2082
		DataElement remoteFile = getElementFor(remotePath);
2083
		
2084
		DataElement queryCmd = getCommandDescriptor(remoteFile, IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS);	
2085
		if (queryCmd != null){
2086
			return true;
2087
		}
2088
		return false;
2089
	}
2090
2091
	public boolean canGetFileOwner(String remoteParent, String name) {
2092
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2093
		DataElement remoteFile = getElementFor(remotePath);
2094
		
2095
		DataElement queryCmd = getCommandDescriptor(remoteFile, IUniversalDataStoreConstants.C_QUERY_FILE_OWNER);	
2096
		if (queryCmd != null){
2097
			return true;
2098
		}
2099
		return false;
2100
	}	
2101
	
2102
	public boolean canSetFilePermissions(String remoteParent, String name) {
2103
		// for now just falling back to the same as get
2104
		return canGetFilePermissions(remoteParent, name);
2105
	}
2106
	
2107
	public boolean canSetFileOwner(String remoteParent, String name) {
2108
		// for now just falling back to the same as get
2109
		return canGetFileOwner(remoteParent, name);
2110
	}
2111
2112
	
2113
	public IHostFilePermissions getFilePermissions(String remoteParent,
2114
			String name, IProgressMonitor monitor)
2115
			throws SystemMessageException {
2116
		
2117
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2118
		DataElement remoteFile = getElementFor(remotePath);
2119
		
2120
		DataElement status = dsStatusCommand(remoteFile, IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS, monitor);
2121
		if (status != null) {					
2122
			int permissionsInt = 0;
2123
			String accessString = status.getSource(); // access string in octal
2124
			if (accessString != null && accessString.length() > 0) {
2125
				try
2126
				{
2127
					int accessInt = Integer.parseInt(accessString, 8);
2128
					String bits = Integer.toString(accessInt, 2);
2129
				    permissionsInt = Integer.parseInt(bits);			    
2130
				}
2131
				catch (Exception e){
2132
					
2133
				}
2134
				HostFilePermissions permissions = new HostFilePermissions(permissionsInt);
2135
				return permissions;
2136
			}
2137
		}
2138
2139
		// nothing - server may not be up-to-date - missing permissions and owner support		
2140
		return null;
2141
	}
2142
2143
	public void setFilePermissions(String remoteParent, String name,
2144
			IHostFilePermissions permissions, IProgressMonitor monitor)
2145
			throws SystemMessageException {
2146
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2147
		DataElement remoteFile = getElementFor(remotePath);
2148
		
2149
		ArrayList args = new ArrayList();
2150
		int bits = permissions.getPermissionBits();
2151
		String permissionsInOctal = Integer.toOctalString(bits);
2152
		
2153
		DataElement newPermissionsElement = getDataStore().createObject(null, "permissions", permissionsInOctal); //$NON-NLS-1$
2154
		args.add(newPermissionsElement);
2155
		
2156
		DataElement status = dsStatusCommand(remoteFile, args, IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS, monitor);
2157
		if (status != null)
2158
		{
2159
			// check status to make sure the file really changed
2160
		}	
2161
	}
2162
2163
	
2164
	public String getFileOwner(String remoteParent, String name,
2165
			IProgressMonitor monitor) throws SystemMessageException {
2166
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2167
		DataElement remoteFile = getElementFor(remotePath);
2168
		
2169
		DataElement status = dsStatusCommand(remoteFile, IUniversalDataStoreConstants.C_QUERY_FILE_OWNER, monitor);
2170
		if (status != null)
2171
		{
2172
			String ownerString = status.getSource();
2173
			if (ownerString != null && ownerString.length() > 0){
2174
				return ownerString;
2175
			}
2176
		}
2177
		
2178
		// nothing - server may not be up-to-date - missing permissions and owner support
2179
		return null;						
2180
	}
2181
2182
	public void setFileOwner(String remoteParent, String name, String newOwner,
2183
			IProgressMonitor monitor) throws SystemMessageException {
2184
2185
		String remotePath = remoteParent + getSeparator(remoteParent) + name;
2186
		DataElement remoteFile = getElementFor(remotePath);
2187
		
2188
		ArrayList args = new ArrayList();
2189
		DataElement newOwnerElement = getDataStore().createObject(null, "owner", newOwner); //$NON-NLS-1$
2190
		args.add(newOwnerElement);
2191
		
2192
		DataElement status = dsStatusCommand(remoteFile, args, IUniversalDataStoreConstants.C_SET_FILE_OWNER, monitor);
2193
		if (status != null)
2194
		{
2195
			// check status to make sure the file really changed
2196
		}						
2197
	}
2198
2199
2200
	
2201
	
2202
	
2070
}
2203
}
(-)src/org/eclipse/rse/services/files/HostFilePermissions.java (+68 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2008 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight.
10
 * 
11
 * Contributors:
12
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
13
 ********************************************************************************/
14
package org.eclipse.rse.services.files;
15
16
/**
17
 * Implementation of IHostFilePermissions.
18
 *
19
 */
20
public class HostFilePermissions implements
21
		IHostFilePermissions {
22
	
23
	private int _permissions = 0;
24
		
25
	/**
26
	 * Constructor that take the initial permissions as a bitmask
27
	 * @param initialPermissions the intial permissions bitmask
28
	 */
29
	public HostFilePermissions(int initialPermissions){
30
		_permissions = initialPermissions;
31
	}
32
		
33
	public void setPermission(int permission, boolean value) {
34
		if (value)
35
			set(permission);
36
		else
37
			clear(permission);
38
	}
39
	
40
	public boolean getPermission(int permission) {
41
		return isSet(permission);
42
	}
43
	
44
	public int getPermissionBits() {
45
		return _permissions;
46
	}
47
	
48
	public void setPermissionBits(int bits) {
49
		_permissions = bits;
50
	}
51
	
52
	public String toString(){
53
		return "" + _permissions;
54
	}
55
	
56
	
57
	private boolean isSet(long mask) {
58
		return (_permissions & mask) != 0;
59
	}
60
61
	private void set(int mask) {
62
		_permissions |= mask;
63
	}
64
	
65
	private void clear(int mask) {
66
		_permissions &= ~mask;
67
	}
68
}
(-)src/org/eclipse/rse/services/files/IHostFilePermissions.java (+117 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2008 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight.
10
 * 
11
 * Contributors:
12
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
13
 ********************************************************************************/
14
package org.eclipse.rse.services.files;
15
16
17
public interface IHostFilePermissions {
18
	
19
	/**
20
	 * Permission constant indicating that 
21
	 * the user can read this file
22
	 */
23
	public static final int PERM_USER_READ = 1 << 8;
24
	
25
	/**
26
	 * Permission constant indicating that 
27
	 * the user can write to this file
28
	 */
29
	public static final int PERM_USER_WRITE = 1 << 7;
30
	
31
	/**
32
	 * Permission constant indicating that 
33
	 * the user can execute this file
34
	 */
35
	public static final int PERM_USER_EXECUTE = 1 << 6;
36
	
37
	/**
38
	 * Permission constant indicating that 
39
	 * the group can read this file
40
	 */
41
	public static final int PERM_GROUP_READ = 1 << 5;
42
	
43
	/**
44
	 * Permission constant indicating that 
45
	 * the group can write to this file
46
	 * 
47
	 */
48
	public static final int PERM_GROUP_WRITE = 1 << 4;
49
	
50
	/**
51
	 * Permission constant indicating that 
52
	 * the group can execute this file
53
	 * 
54
	 */
55
	public static final int PERM_GROUP_EXECUTE = 1 << 3;
56
	
57
	/**
58
	 * Permission constant indicating that 
59
	 * other users can read this file
60
	 * 
61
	 */
62
	public static final int PERM_OTHER_READ = 1 << 2;
63
	
64
	/**
65
	 * Permission constant indicating that 
66
	 * other users can write to this file
67
	 * 
68
	 */
69
	public static final int PERM_OTHER_WRITE = 1 << 1;
70
	
71
	/**
72
	 * Permission constant indicating that 
73
	 * other users can execute to this file
74
	 * 
75
	 */
76
	public static final int PERM_OTHER_EXECUTE = 1 << 0;
77
	
78
79
	// support masks
80
	public static final int PERM_ANY_READ = PERM_USER_READ | PERM_GROUP_READ | PERM_OTHER_READ;
81
	public static final int PERM_ANY_WRITE = PERM_USER_WRITE | PERM_GROUP_WRITE | PERM_OTHER_WRITE;
82
	public static final int PERM_ANY_EXECUTE = PERM_USER_EXECUTE | PERM_GROUP_EXECUTE | PERM_OTHER_EXECUTE;
83
84
	/**
85
	 * Set or reset all the permission bits from the given bitmask.
86
	 * 
87
	 * @param bitmask the permission(s) bits to modify
88
	 * @param value whether to turn on off of the permission(s)
89
	 * 
90
	 * Example: setPermission(PERM_USER_WRITE | PERM_GROUP_WRITE, true);
91
	 */
92
	public void setPermission(int bitmask, boolean value);
93
	
94
	/**
95
	 * Test if any of the permission bits from the bitmask are set.
96
	 * 
97
	 * @param bitmask the permission(s) to check for
98
	 * @return true if one of the permission bits is set
99
	 * 
100
	 * Example: getPermission(PERM_USER_WRITE | PERM_GROUP_WRITE)
101
	 */
102
	public boolean getPermission(int bitmask);
103
104
	/**
105
	 * Get the set of permission bits.
106
	 * 
107
	 * @return set of permission bits
108
	 */
109
	public int getPermissionBits();
110
	
111
	/**
112
	 * Set the permission bits
113
	 * @param bits the set of permission bits
114
	 */
115
	public void setPermissionBits(int bits);
116
117
}
(-)src/org/eclipse/rse/services/files/IFileOwnerService.java (+62 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2008 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight.
10
 * 
11
 * Contributors:
12
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
13
 ********************************************************************************/
14
package org.eclipse.rse.services.files;
15
16
import org.eclipse.core.runtime.IProgressMonitor;
17
18
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
19
20
/**
21
 * Service used to get and set the owner of a file.
22
 */
23
public interface IFileOwnerService {
24
	/**
25
	 * @param remoteParent
26
	 * @param name
27
	 * @param monitor the monitor for this potentially long running operation
28
	 * @return the host file owner
29
	 * @throws SystemMessageException if an error occurs. 
30
	 * Typically this would be one of those in the RemoteFileException family.
31
	 */
32
	public String getFileOwner(String remoteParent, String name, IProgressMonitor monitor) throws SystemMessageException;
33
34
	/**
35
	 * @param remoteParent
36
	 * @param name
37
	 * @param monitor the monitor for this potentially long running operation
38
	 * @throws SystemMessageException if an error occurs. 
39
	 * Typically this would be one of those in the RemoteFileException family.
40
	 */
41
	public void setFileOwner(String remoteParent, String name, String newOwner, IProgressMonitor monitor) throws SystemMessageException;
42
43
	/**
44
	 * Indicates whether the file owner can be retrieved for the specified file
45
	 * In some cases the service will need to determine whether it supports ownership 
46
	 * depending on the current server.
47
	 * 
48
	 * @param remoteParent the
49
	 * @param name  
50
	 * @return whether the file owner can be retrieved
51
	 */
52
	public boolean canGetFileOwner(String remoteParent, String name);
53
	
54
	/**
55
	 * Indicates whether the file owner can be set for the specified file
56
	 * 
57
	 * @param remoteParent the
58
	 * @param name  
59
	 * @return whether the file owner can be set
60
	 */
61
	public boolean canSetFileOwner(String remoteParent, String name);
62
}
(-)src/org/eclipse/rse/services/files/IFilePermissionsService.java (+64 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2008 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight.
10
 * 
11
 * Contributors:
12
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
13
 ********************************************************************************/
14
package org.eclipse.rse.services.files;
15
16
import org.eclipse.core.runtime.IProgressMonitor;
17
18
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
19
20
/**
21
 * Service used to get and set the permissions of a file.
22
 */
23
public interface IFilePermissionsService {
24
25
	/**
26
	 * @param remoteParent
27
	 * @param name
28
	 * @param monitor the monitor for this potentially long running operation
29
	 * @return the host file permissions
30
	 * @throws SystemMessageException if an error occurs. 
31
	 * Typically this would be one of those in the RemoteFileException family.
32
	 */
33
	public IHostFilePermissions getFilePermissions(String remoteParent, String name, IProgressMonitor monitor) throws SystemMessageException;
34
	
35
	/**
36
	 * @param remoteParent
37
	 * @param name
38
	 * @param permissions the new permissions for this file
39
	 * @param monitor the monitor for this potentially long running operation
40
	 * @throws SystemMessageException if an error occurs. 
41
	 * Typically this would be one of those in the RemoteFileException family.
42
	 */
43
	public void setFilePermissions(String remoteParent, String name, IHostFilePermissions permissions, IProgressMonitor monitor) throws SystemMessageException;
44
45
	/**
46
	 * Indicates whether the file permissions can be retrieved for the specified file.  
47
	 * In some cases the service will need to determine whether it supports permissions 
48
	 * depending on the current server.
49
	 * 
50
	 * @param remoteParent
51
	 * @param name  
52
	 * @return whether the file permissions can be retrieved
53
	 */
54
	public boolean canGetFilePermissions(String remoteParent, String name);
55
	
56
	/**
57
	 * Indicates whether the file permissions can be set for the specified file
58
	 * 
59
	 * @param remoteParent
60
	 * @param name  
61
	 * @return whether the file permissions can be set
62
	 */
63
	public boolean canSetFilePermissions(String remoteParent, String name);
64
}

Return to bug 209593