Added: hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chmod.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chmod.bat?rev=1400262&view=auto ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chmod.bat (added) +++ hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chmod.bat Fri Oct 19 20:13:06 2012 @@ -0,0 +1,174 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +echo Test various chmod operations +setlocal +set WINUTILS="%HADOOP_HOME%\bin\winutils.exe" +set TESTDIR=winutils-test + +:: Setup test directory +:: +if not exist %TESTDIR% md %TESTDIR% +pushd %TESTDIR% + +:: Test cases +:: +echo Test case 1: +call:TestChmod "7" "------rwx" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 2: +call:TestChmod "70" "---rwx---" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 3: +call:TestChmod "u-x,g+r,o=g" "rw-r--r--" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 4: +call:TestChmod "u-x,g+rw" "rw-rw----" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 5: +call:TestChmod "u-x,g+rwx-x,o=u" "rw-rw-rw-" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 6: +call:TestChmodR "755" "rwxr-xr-x" "rwxr-xr-x" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 7: +call:TestChmodR "u-x,g+r,o=g" "rw-r--r--" "rw-r--r--" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 8: +call:TestChmodR "u-x,g+rw" "rw-rw----" "rw-rw----" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 9: +call:TestChmodR "u-x,g+rwx-x,o=u" "rw-rw-rw-" "rw-rw-rw-" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 10: +call:TestChmodR "a+rX" "rw-r--r--" "rwxr-xr-x" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 11: +call:TestChmod "+" "rwx------" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +:: Cleanup +:: +popd +rd %TESTDIR% +goto Success + + +:: ----------------------------------------------------------------------------- +:: -- Function section starts below here +:: ----------------------------------------------------------------------------- + + +:: TestChmod +:: - Test 'chmod' mode or octal mode string of a single file +:: - The new permission will be compared with the expected result +:: +:TestChmod :: [mode|octal mode] [expected permission] +if exist a exit /B 1 +type NUL>a +%WINUTILS% chmod 700 a +%WINUTILS% chmod %~1 a +call:CmpPerm "a" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +del a +exit /B 0 + + +:: TestChmodR +:: - Test 'chmod' mode or octal mode string with recursive option +:: - The new permission will be compared with the expected results +:: - The permissions could be different due to 'X' in mode string +:: +:TestChmodR :: [mode|octal mode] [expected permission] [expected permission x] +if exist a exit /B 1 +md a +%WINUTILS% chmod 700 a +type NUL>a\a +%WINUTILS% chmod 600 a\a +md a\b +%WINUTILS% chmod 700 a\b +md a\b\a +%WINUTILS% chmod 700 a\b\a +type NUL>a\b\b +%WINUTILS% chmod 600 a\b\b +type NUL>a\b\x +%WINUTILS% chmod u+x a\b\x + +%WINUTILS% chmod -R %~1 a + +call:CmpPerm "a" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\a" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\a" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\b" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\x" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 + +rd /S /Q a +exit /B 0 + + +:: CmpPerm +:: - Compare file permission against given permission +:: - Use 'ls' to get the new permission +:: - Exit with errorlevel > 0 on failure +:: +:CmpPerm :: [file] [perm] +for /F "tokens=1" %%A in ('call %WINUTILS% ls %~1') do set PERM=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +if not %PERM:~-9%==%~2 exit /B 1 +exit /B 0 + + +:: Failure +:: - Report test failure +:: +:Failure +echo Test failed. +exit /B 1 + +:: Success +:: - Report test success +:: +:Success +echo Test succeeded. +exit /B 0
Added: hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chown.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chown.bat?rev=1400262&view=auto ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chown.bat (added) +++ hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/tests/test-winutils-chown.bat Fri Oct 19 20:13:06 2012 @@ -0,0 +1,95 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +echo Test chown operations +setlocal +set WINUTILS="%HADOOP_HOME%\bin\winutils.exe" +set TESTDIR=winutils-test + +:: Setup test directory +:: +if not exist %TESTDIR% md %TESTDIR% +pushd %TESTDIR% + +:: Get username +:: +for /F "tokens=1" %%A in ('call whoami') do set USER=%%A + +:: Test cases +:: +echo Test case 1: +if exist a goto Failure +type NUL>a +%WINUTILS% chown %USER%:Administrators 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. + +echo Test case 2: +if exist a goto Failure +type NUL>a +%WINUTILS% chown %USER% a +if not %ERRORLEVEL% == 0 goto Failure +%WINUTILS% chown :Administrators 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 +:: +popd +rd %TESTDIR% +goto Success + +:: ----------------------------------------------------------------------------- +:: -- Function section starts below here +:: ----------------------------------------------------------------------------- + +:: CmpOwn +:: - Compare file ownership against expected owner +:: - Use 'ls' to get the ownership +:: - Exit with errorlevel > 0 on failure +:: +:CmpOwn :: [file] [expected user owner] [expected group owner] +for /F "tokens=3" %%A in ('call %WINUTILS% ls %~1') do set OWNER=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +for /F "tokens=4" %%A in ('call %WINUTILS% ls %~1') do set GROUP=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +if /I not %OWNER%==%~2 exit /B 1 +if /I not %GROUP%==%~3 exit /B 1 +exit /B 0 + + +:: Failure +:: - Report test failure +:: +:Failure +echo Test failed. +exit /B 1 + +:: Success +:: - Report test success +:: +:Success +echo Test succeeded. +exit /B 0 Added: hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.sln URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.sln?rev=1400262&view=auto ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.sln (added) +++ hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.sln Fri Oct 19 20:13:06 2012 @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winutils", "winutils.vcxproj", "{D94B3BD7-39CC-47A0-AE9A-353FDE506F33}" + ProjectSection(ProjectDependencies) = postProject + {12131AA7-902E-4A6D-9CE3-043261D22A12} = {12131AA7-902E-4A6D-9CE3-043261D22A12} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwinutils", "libwinutils.vcxproj", "{12131AA7-902E-4A6D-9CE3-043261D22A12}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Debug|Win32.ActiveCfg = Debug|x64 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Debug|Win32.Build.0 = Debug|x64 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Debug|x64.ActiveCfg = Debug|x64 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Debug|x64.Build.0 = Debug|x64 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Release|Win32.ActiveCfg = Release|Win32 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Release|Win32.Build.0 = Release|Win32 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Release|x64.ActiveCfg = Release|x64 + {D94B3BD7-39CC-47A0-AE9A-353FDE506F33}.Release|x64.Build.0 = Release|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Debug|Win32.ActiveCfg = Debug|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Debug|Win32.Build.0 = Debug|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Debug|x64.ActiveCfg = Debug|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Debug|x64.Build.0 = Debug|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Release|Win32.ActiveCfg = Release|Win32 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Release|Win32.Build.0 = Release|Win32 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Release|x64.ActiveCfg = Release|x64 + {12131AA7-902E-4A6D-9CE3-043261D22A12}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal Added: hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj?rev=1400262&view=auto ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj (added) +++ hadoop/common/branches/branch-trunk-win/hadoop-common-project/hadoop-common/src/main/winutils/winutils.vcxproj Fri Oct 19 20:13:06 2012 @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{D94B3BD7-39CC-47A0-AE9A-353FDE506F33}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>winutils</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup> + <IncludePath>include;$(IncludePath)</IncludePath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level4</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="symlink.c" /> + <ClCompile Include="systeminfo.c" /> + <ClCompile Include="chmod.c" /> + <ClCompile Include="chown.c" /> + <ClCompile Include="groups.c" /> + <ClCompile Include="hardlink.c" /> + <ClCompile Include="task.c" /> + <ClCompile Include="ls.c" /> + <ClCompile Include="main.c" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="libwinutils.vcxproj"> + <Project>{12131aa7-902e-4a6d-9ce3-043261d22a12}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file
