You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by vi...@apache.org on 2012/10/20 01:40:55 UTC
svn commit: r1400342 - in /hadoop/common/branches/branch-1-win: ./
src/core/org/apache/hadoop/fs/ src/winutils/ src/winutils/tests/
Author: vinodkv
Date: Fri Oct 19 23:40:54 2012
New Revision: 1400342
URL: http://svn.apache.org/viewvc?rev=1400342&view=rev
Log:
HADOOP-8763. Implement set-group-owner for Windows correctly. Contributed by Chuan Liu.
Modified:
hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/FileUtil.java
hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
hadoop/common/branches/branch-1-win/src/winutils/chown.c
hadoop/common/branches/branch-1-win/src/winutils/libwinutils.c
hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat
Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Fri Oct 19 23:40:54 2012
@@ -175,3 +175,6 @@ Branch-hadoop-1-win - unreleased
HADOOP-8899. Classpath exceeds maximum Windows command limit.
(Ahmed El Baz via suresh)
+
+ HADOOP-8763. Implement set-group-owner for Windows correctly. (Chuan Liu via
+ vinodkv)
Modified: hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/FileUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/FileUtil.java?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/FileUtil.java (original)
+++ hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/FileUtil.java Fri Oct 19 23:40:54 2012
@@ -661,6 +661,25 @@ public class FileUtil {
}
/**
+ * Set the ownership on a file / directory. User name and group name
+ * cannot both be null.
+ * @param file the file to change
+ * @param username the new user owner name
+ * @param groupname the new group owner name
+ * @throws IOException
+ */
+ public static void setOwner(File file, String username,
+ String groupname) throws IOException {
+ if (username == null && groupname == null) {
+ throw new IOException("username == null && groupname == null");
+ }
+ String arg = (username == null ? "" : username)
+ + (groupname == null ? "" : ":" + groupname);
+ String [] cmd = Shell.getSetOwnerCommand(arg);
+ execCommand(file, cmd);
+ }
+
+ /**
* Set permissions to the required value. Uses the java primitives instead
* of forking if group == other.
* @param f the file to change
Modified: hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java (original)
+++ hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java Fri Oct 19 23:40:54 2012
@@ -558,17 +558,7 @@ public class RawLocalFileSystem extends
@Override
public void setOwner(Path p, String username, String groupname
) throws IOException {
- if (username == null && groupname == null) {
- throw new IOException("username == null && groupname == null");
- }
-
- if (username == null) {
- FileUtil.execCommand(pathToFile(p), Shell.SET_GROUP_COMMAND, groupname);
- } else {
- //OWNER[:[GROUP]]
- String s = username + (groupname == null? "": ":" + groupname);
- FileUtil.execCommand(pathToFile(p), Shell.getSetOwnerCommand(s));
- }
+ FileUtil.setOwner(pathToFile(p), username, groupname);
}
/**
Modified: hadoop/common/branches/branch-1-win/src/winutils/chown.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/chown.c?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/chown.c (original)
+++ hadoop/common/branches/branch-1-win/src/winutils/chown.c Fri Oct 19 23:40:54 2012
@@ -353,7 +353,7 @@ int Chown(int argc, wchar_t *argv[])
goto ChownEnd;
}
- if (colonPos + 1 != NULL)
+ if (*(colonPos + 1) != 0)
{
// Length includes NULL terminator
groupNameLen = wcslen(ownerInfo) - (colonPos - ownerInfo) + 1;
@@ -382,10 +382,16 @@ int Chown(int argc, wchar_t *argv[])
goto ChownEnd;
}
- if ((userName == NULL || wcslen(userName) == 0) &&
- (groupName == NULL || wcslen(groupName) == 0))
+ // Not allow zero length user name or group name in the parsing results.
+ //
+ assert(userName == NULL || wcslen(userName) > 0);
+ assert(groupName == NULL || wcslen(groupName) > 0);
+
+ // Nothing to change if both names are empty
+ //
+ if ((userName == NULL) && (groupName == NULL))
{
- fwprintf(stderr, L"User name and group name cannot both be empty.");
+ ret = EXIT_SUCCESS;
goto ChownEnd;
}
@@ -493,6 +499,11 @@ void ChownUsage(LPCWSTR program)
{
fwprintf(stdout, L"\
Usage: %s [OWNER][:[GROUP]] [FILE]\n\
-Change the owner and/or group of the FILE to OWNER and/or GROUP.\n",
+Change the owner and/or group of the FILE to OWNER and/or GROUP.\n\
+\n\
+Note:\n\
+On Linux, if a colon but no group name follows the user name, the group of\n\
+the files is changed to that user\'s login group. Windows has no concept of\n\
+a user's login group. So we do not change the group owner in this case.\n",
program);
}
Modified: hadoop/common/branches/branch-1-win/src/winutils/libwinutils.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/libwinutils.c?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/libwinutils.c (original)
+++ hadoop/common/branches/branch-1-win/src/winutils/libwinutils.c Fri Oct 19 23:40:54 2012
@@ -413,10 +413,13 @@ DWORD GetSidFromAcctNameW(LPCWSTR acctNa
assert (acctName != NULL && ppSid != NULL);
// Empty name is invalid. However, LookupAccountName() function will return a
- // false Sid for an empty name instead failing.
+ // false Sid, i.e. Sid for 'BUILDIN', for an empty name instead failing. We
+ // report the error before calling LookupAccountName() function for this
+ // special case. The error code returned here is the same as the last error
+ // code set by LookupAccountName() function for an invalid name.
//
if (wcslen(acctName) == 0)
- return FALSE;
+ return ERROR_NONE_MAPPED;
// First pass to retrieve the buffer size.
//
Modified: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat?rev=1400342&r1=1400341&r2=1400342&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat (original)
+++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat Fri Oct 19 23:40:54 2012
@@ -54,6 +54,19 @@ del a
if not %ERRORLEVEL% == 0 goto Failure
echo passed.
+echo Test case 3:
+if exist a goto Failure
+type NUL>a
+%WINUTILS% chown :Administrators a
+if not %ERRORLEVEL% == 0 goto Failure
+%WINUTILS% chown %USER%: a
+if not %ERRORLEVEL% == 0 goto Failure
+call:CmpOwn "a" "%USER%" "BUILTIN\Administrators"
+if not %ERRORLEVEL% == 0 goto Failure
+del a
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
:: Cleanup
::