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 su...@apache.org on 2013/05/03 00:39:57 UTC
svn commit: r1478592 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt
src/main/winutils/include/winutils.h src/main/winutils/main.c
src/main/winutils/winutils.vcxproj
src/test/java/org/apache/hadoop/util/TestWinUtils.java
Author: suresh
Date: Thu May 2 22:39:56 2013
New Revision: 1478592
URL: http://svn.apache.org/r1478592
Log:
HADOOP-9483. winutils support for readlink command. Contributed by Arpit Agarwal.
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/include/winutils.h
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/main.c
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1478592&r1=1478591&r2=1478592&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Thu May 2 22:39:56 2013
@@ -542,6 +542,9 @@ Trunk (Unreleased)
HADOOP-9043. Disallow in winutils creating symlinks with forwards slashes.
(Chris Nauroth and Arpit Agarwal via suresh)
+
+ HADOOP-9483. winutils support for readlink command.
+ (Arpit Agarwal via suresh)
Release 2.0.5-beta - UNRELEASED
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/include/winutils.h
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/include/winutils.h?rev=1478592&r1=1478591&r2=1478592&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/include/winutils.h (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/include/winutils.h Thu May 2 22:39:56 2013
@@ -104,6 +104,9 @@ void TaskUsage();
int Symlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
void SymlinkUsage();
+int Readlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
+void ReadlinkUsage();
+
int SystemInfo();
void SystemInfoUsage();
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/main.c
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/main.c?rev=1478592&r1=1478591&r2=1478592&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/main.c (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/main.c Thu May 2 22:39:56 2013
@@ -55,6 +55,10 @@ int wmain(__in int argc, __in_ecount(arg
{
return Symlink(argc - 1, argv + 1);
}
+ else if (wcscmp(L"readlink", cmd) == 0)
+ {
+ return Readlink(argc - 1, argv + 1);
+ }
else if (wcscmp(L"task", cmd) == 0)
{
return Task(argc - 1, argv + 1);
@@ -105,6 +109,10 @@ The available commands and their usages
SymlinkUsage();
fwprintf(stdout, L"\n\n");
+ fwprintf(stdout, L"%-10s%s\n\n", L"readlink", L"Print the target of a symbolic link.");
+ ReadlinkUsage();
+ fwprintf(stdout, L"\n\n");
+
fwprintf(stdout, L"%-15s%s\n\n", L"systeminfo", L"System information.");
SystemInfoUsage();
fwprintf(stdout, L"\n\n");
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj?rev=1478592&r1=1478591&r2=1478592&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj Thu May 2 22:39:56 2013
@@ -160,6 +160,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="readlink.c" />
<ClCompile Include="symlink.c" />
<ClCompile Include="systeminfo.c" />
<ClCompile Include="chmod.c" />
@@ -178,4 +179,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java?rev=1478592&r1=1478591&r2=1478592&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java Thu May 2 22:39:56 2013
@@ -33,6 +33,8 @@ import org.apache.hadoop.fs.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assume.*;
+import static org.hamcrest.CoreMatchers.*;
/**
* Test cases for helper Windows winutils.exe utility.
@@ -359,4 +361,85 @@ public class TestWinUtils {
"Expected: Failed to create symlink with forward slashes in target");
}
}
+
+ @Test (timeout = 30000)
+ public void testReadLink() throws IOException {
+ // Create TEST_DIR\dir1\file1.txt
+ //
+ File dir1 = new File(TEST_DIR, "dir1");
+ assertTrue(dir1.mkdirs());
+
+ File file1 = new File(dir1, "file1.txt");
+ assertTrue(file1.createNewFile());
+
+ File dirLink = new File(TEST_DIR, "dlink");
+ File fileLink = new File(TEST_DIR, "flink");
+
+ // Next create a directory symlink to dir1 and a file
+ // symlink to file1.txt.
+ //
+ Shell.execCommand(
+ Shell.WINUTILS, "symlink", dirLink.toString(), dir1.toString());
+ Shell.execCommand(
+ Shell.WINUTILS, "symlink", fileLink.toString(), file1.toString());
+
+ // Read back the two links and ensure we get what we expected.
+ //
+ String readLinkOutput = Shell.execCommand(Shell.WINUTILS,
+ "readlink",
+ dirLink.toString());
+ assertThat(readLinkOutput, equalTo(dir1.toString()));
+
+ readLinkOutput = Shell.execCommand(Shell.WINUTILS,
+ "readlink",
+ fileLink.toString());
+ assertThat(readLinkOutput, equalTo(file1.toString()));
+
+ // Try a few invalid inputs and verify we get an ExitCodeException for each.
+ //
+ try {
+ // No link name specified.
+ //
+ Shell.execCommand(Shell.WINUTILS, "readlink", "");
+ fail("Failed to get Shell.ExitCodeException when reading bad symlink");
+ } catch (Shell.ExitCodeException ece) {
+ assertThat(ece.getExitCode(), is(1));
+ }
+
+ try {
+ // Bad link name.
+ //
+ Shell.execCommand(Shell.WINUTILS, "readlink", "ThereIsNoSuchLink");
+ fail("Failed to get Shell.ExitCodeException when reading bad symlink");
+ } catch (Shell.ExitCodeException ece) {
+ assertThat(ece.getExitCode(), is(1));
+ }
+
+ try {
+ // Non-symlink directory target.
+ //
+ Shell.execCommand(Shell.WINUTILS, "readlink", dir1.toString());
+ fail("Failed to get Shell.ExitCodeException when reading bad symlink");
+ } catch (Shell.ExitCodeException ece) {
+ assertThat(ece.getExitCode(), is(1));
+ }
+
+ try {
+ // Non-symlink file target.
+ //
+ Shell.execCommand(Shell.WINUTILS, "readlink", file1.toString());
+ fail("Failed to get Shell.ExitCodeException when reading bad symlink");
+ } catch (Shell.ExitCodeException ece) {
+ assertThat(ece.getExitCode(), is(1));
+ }
+
+ try {
+ // Too many parameters.
+ //
+ Shell.execCommand(Shell.WINUTILS, "readlink", "a", "b");
+ fail("Failed to get Shell.ExitCodeException with bad parameters");
+ } catch (Shell.ExitCodeException ece) {
+ assertThat(ece.getExitCode(), is(1));
+ }
+ }
}