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 |
} |