hadoop-tools 0.6 → 0.7
raw patch · 6 files changed
+53/−33 lines, 6 filesdep ~base
Dependency ranges changed: base
Files
- bash-completion +0/−14
- hadoop-tools.cabal +10/−7
- hh-completion.bash +14/−0
- src/Chmod.hs +1/−2
- src/Glob.hs +3/−2
- src/Main.hs +25/−8
− bash-completion
@@ -1,14 +0,0 @@-#!/bin/bash-_hh()-{- local cmdline- CMDLINE=(--bash-completion-index $COMP_CWORD)-- for arg in ${COMP_WORDS[@]}; do- CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)- done-- COMPREPLY=( $(hh "${CMDLINE[@]}") )-}--complete -o nospace -F _hh hh
hadoop-tools.cabal view
@@ -1,5 +1,5 @@ name: hadoop-tools-version: 0.6+version: 0.7 synopsis: Fast command line tools for working with Hadoop.@@ -7,11 +7,10 @@ description: hh - Blazing fast interaction with HDFS .- If built against hadoop-rpc-1.x.x.x then these tools support v9 of the- Hadoop RPC protocol (CDH 5.x and above).+ These tools support v9 of the Hadoop RPC protocol (CDH 5.x and above). .- Earlier versions (< 0.6) can be installed using- --constraint=hadoop-rpc==0.1.1.1 if you need v7 support.+ Earlier versions (< 0.6) can be installed using --constraint=hadoop-rpc==0.1.1.1+ if you need v7 support. . > hh cat - Print the contents of a file to stdout > hh cd - Change working directory@@ -36,7 +35,7 @@ cabal-version: >= 1.10 extra-source-files:- bash-completion+ hh-completion.bash executable hh default-language: Haskell2010@@ -53,7 +52,7 @@ Paths_hadoop_tools build-depends:- base >= 4.7 && < 5+ base >= 4.8 && < 5 , attoparsec >= 0.12 , boxes >= 0.1 , bytestring >= 0.10@@ -90,3 +89,7 @@ , tasty-hunit , tasty-quickcheck , vector++source-repository head+ type: git+ location: https://github.com/jystic/hadoop-tools.git
+ hh-completion.bash view
@@ -0,0 +1,14 @@+#!/bin/bash+_hh()+{+ local cmdline+ CMDLINE=(--bash-completion-index $COMP_CWORD)++ for arg in ${COMP_WORDS[@]}; do+ CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)+ done++ COMPREPLY=( $(hh "${CMDLINE[@]}") )+}++complete -o nospace -F _hh hh
src/Chmod.hs view
@@ -6,7 +6,6 @@ , applyChmod ) where -import Control.Applicative import Control.Monad (guard, msum) import qualified Data.Attoparsec.ByteString.Char8 as Atto import Data.Bits@@ -102,7 +101,7 @@ minus :: ChmodWho -> Word16 -> Word16 -> Word16 minus who old new = old `xor` setWho who new - foldRWX old = foldl' (\old what -> old .|. b what) 0 . mapMaybe (hX old)+ foldRWX old = foldl' (\old' what -> old' .|. b what) 0 . mapMaybe (hX old) o3 u g o = u*64 + g*8 + o
src/Glob.hs view
@@ -8,7 +8,6 @@ ------------------------------------------------------------------------ -import Control.Applicative ((<$>)) import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B import Data.Monoid ((<>))@@ -49,7 +48,9 @@ escape :: Char -> String escape c | c `elem` regexChars = '\\' : [c] | otherwise = [c]- where regexChars = "\\+()^$.{}]|"+ where+ regexChars :: [Char]+ regexChars = "\\+()^$.{}]|" charClass :: String -> String charClass (']':cs) = ']' : globToRegex' cs
src/Main.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE ScopedTypeVariables #-} module Main (main) where @@ -12,7 +13,6 @@ import Data.Bits ((.&.), shiftL, shiftR) import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B-import Data.Foldable (foldMap) import Data.Maybe (fromMaybe) import qualified Data.Text as T import qualified Data.Text.Encoding as T@@ -32,7 +32,6 @@ import qualified System.FilePath.Posix as Posix import System.IO import System.IO.Unsafe (unsafePerformIO)-import System.Locale (defaultTimeLocale) import System.Posix.User (GroupEntry(..), getGroups, getGroupEntryForID) import Text.PrettyPrint.Boxes hiding ((<>), (//)) @@ -54,17 +53,32 @@ cmd <- execParser optsParser case cmd of SubIO io -> io- SubHdfs hdfs -> handle exitError (runHdfs hdfs)+ SubHdfs hdfs -> runHdfs hdfs where optsParser = info (helper <*> options) (fullDesc <> header "hh - Blazing fast interaction with HDFS")- exitError err = printError err >> exitFailure -runHdfs :: Hdfs a -> IO a-runHdfs hdfs = do+runHdfs :: forall a. Hdfs a -> IO a+runHdfs hdfs = handle exitError $ do config <- getConfig- runHdfs' config hdfs+ run config+ where+ exitError :: RemoteError -> IO a+ exitError err = printError err >> exitFailure + run :: HadoopConfig -> IO a+ run cfg = handle (runAgain cfg) (print cfg >> runHdfs' cfg hdfs)++ runAgain :: HadoopConfig -> RemoteError -> IO a+ runAgain cfg e | isStandbyError e = maybe (throwM e) run (dropNameNode cfg)+ | otherwise = throwM e++ dropNameNode :: HadoopConfig -> Maybe HadoopConfig+ dropNameNode cfg | null ns = Nothing+ | otherwise = Just (cfg { hcNameNodes = ns })+ where+ ns = drop 1 (hcNameNodes cfg)+ getConfig :: IO HadoopConfig getConfig = do hdfsUser <- getHdfsUser@@ -349,7 +363,7 @@ <*> switch (short 'r' <> help "Test read permission is granted") <*> switch (short 'w' <> help "Test write permission is granted") <*> switch (short 'x' <> help "Test exectute permission is granted")- test path e z d f l r w x = SubHdfs $ do+ test path _e z d f l r w x = SubHdfs $ do absPath <- getAbsolute path minfo <- getFileInfo absPath user <- liftIO getHadoopUser@@ -562,6 +576,9 @@ isAccessDenied :: RemoteError -> Bool isAccessDenied (RemoteError s _) = s == "org.apache.hadoop.security.AccessControlException"++isStandbyError :: RemoteError -> Bool+isStandbyError (RemoteError s _) = s == "org.apache.hadoop.ipc.StandbyException" ------------------------------------------------------------------------