eliminate showStart showStartOther
authorJoey Hess <joeyh@joeyh.name>
Mon, 10 Apr 2023 20:07:54 +0000 (16:07 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 10 Apr 2023 20:28:58 +0000 (16:28 -0400)
These were not handling control characters and are redundant.

Sponsored-by: Jack Hill on Patreon
Assistant/Threads/Committer.hs
Command/FuzzTest.hs
Command/ImportFeed.hs
Command/Info.hs
Command/Map.hs
Messages.hs
doc/todo/terminal_escapes_in_filenames.mdwn

index d11efda3e262a5e2ab6bd24e375ae5b782980d45..8929a722af651de026f7d7f54d8ffc6d7802942e 100644 (file)
@@ -333,7 +333,7 @@ handleAdds lockdowndir havelsof largefilematcher delayadd cs = returnWhen (null
                ks = keySource ld
                doadd = sanitycheck ks $ do
                        (mkey, _mcache) <- liftAnnex $ do
-                               showStart "add" (keyFilename ks) (SeekInput [])
+                               showStartMessage (StartMessage "add" (ActionItemOther (Just (QuotedPath (keyFilename ks)))) (SeekInput []))
                                ingest nullMeterUpdate (Just $ LockedDown lockdownconfig ks) Nothing
                        maybe (failedingest change) (done change $ fromRawFilePath $ keyFilename ks) mkey
        addannexed' _ _ = return Nothing
index 4fadffce30f1062379fc8aa6b530c956784d521d..642f07b51df6e2fb757f070834d094ed7bdf56a1 100644 (file)
@@ -37,7 +37,7 @@ start :: CommandStart
 start = do
        guardTest
        logf <- fromRepo gitAnnexFuzzTestLogFile
-       showStart "fuzztest" (toRawFilePath logf) (SeekInput [])
+       showStartMessage (StartMessage "fuzztest" (ActionItemOther (Just (UnquotedString logf))) (SeekInput []))
        logh <- liftIO $ openFile logf WriteMode
        void $ forever $ fuzz logh
        stop
index 2b6803024fc2b8f1cd55df40576c8a5f6bd021c0..07c289d7cedef0dc33b1b53d31f729d9771ab732 100644 (file)
@@ -81,7 +81,7 @@ seek o = do
 
 getFeed :: AddUnlockedMatcher -> ImportFeedOptions -> Cache -> URLString -> CommandSeek
 getFeed addunlockedmatcher opts cache url = do
-       showStartOther "importfeed" (Just url) (SeekInput [])
+       showStartMessage (StartMessage "importfeed" (ActionItemOther (Just (UnquotedString url))) (SeekInput []))
        withTmpFile "feed" $ \tmpf h -> do
                liftIO $ hClose h
                ifM (downloadFeed url tmpf)
@@ -148,7 +148,7 @@ getCache :: Maybe String -> Annex Cache
 getCache opttemplate = ifM (Annex.getRead Annex.force)
        ( ret S.empty S.empty
        , do
-               showStart "importfeed" "gathering known urls" (SeekInput [])
+               showStartMessage (StartMessage "importfeed" (ActionItemOther (Just "gathering known urls")) (SeekInput []))
                (us, is) <- knownItems
                showEndOk
                ret (S.fromList us) (S.fromList is)
@@ -373,7 +373,7 @@ performDownload' started addunlockedmatcher opts cache todownload = case locatio
                        )
 
        starturl u = unless started $
-               showStartOther "addurl" (Just u) (SeekInput [])
+               showStartMessage (StartMessage "addurl" (ActionItemOther (Just (UnquotedString u))) (SeekInput []))
 
 defaultTemplate :: String
 defaultTemplate = "${feedtitle}/${itemtitle}${extension}"
index 422d2f88d29e078687faf35c624870311c3ce9ca..b6d12841f1f88d61ec4ee903881bb7ff6a5742bd 100644 (file)
@@ -182,7 +182,7 @@ itemInfo o (si, p) = ifM (isdir (toRawFilePath p))
 
 noInfo :: String -> SeekInput -> String -> Annex ()
 noInfo s si msg = do
-       showStart "info" (encodeBS s) si
+       showStartMessage (StartMessage "info" (ActionItemOther (Just (UnquotedString s))) si)
        showNote msg
        showEndFail
        Annex.incError
index bdebbc4b1fca0e6c3bac4a0020cfac39fc43a7d7..2674fac5010c07510a5dc37184e06106c0669de0 100644 (file)
@@ -196,7 +196,7 @@ same a b
 {- reads the config of a remote, with progress display -}
 scan :: Git.Repo -> Annex Git.Repo
 scan r = do
-       showStartOther "map" (Just $ Git.repoDescribe r) (SeekInput [])
+       showStartMessage (StartMessage "map" (ActionItemOther (Just $ UnquotedString $ Git.repoDescribe r)) (SeekInput []))
        v <- tryScan r
        case v of
                Just r' -> do
index 45b7de6209b627d969fc16b94be890535bc64cc7..5b6ed426f978268e1e538b7699cf7f2ffde6572d 100644 (file)
@@ -8,8 +8,6 @@
 {-# LANGUAGE OverloadedStrings #-}
 
 module Messages (
-       showStart,
-       showStartOther,
        showStartMessage,
        showEndMessage,
        StartMessage(..),
@@ -70,32 +68,6 @@ import Annex.Concurrent.Utility
 import qualified Messages.JSON as JSON
 import qualified Annex
 
-showStart :: String -> RawFilePath -> SeekInput -> Annex ()
-showStart command file si = outputMessage json $
-       encodeBS command <> " " <> file <> " "
-  where
-       json = JSON.start command (Just file) Nothing si
-
-showStartActionItem :: String -> ActionItem -> SeekInput -> Annex ()
-showStartActionItem command ai si = do
-       qp <- coreQuotePath <$> Annex.getGitConfig
-       outputMessage json $
-               encodeBS command <> " " <> actionItemDesc qp ai <> " "
-  where
-       json = JSON.start command (actionItemFile ai) (actionItemKey ai) si
-
-showStartOther :: String -> Maybe String -> SeekInput -> Annex ()
-showStartOther command mdesc si = outputMessage json $ encodeBS $
-       command ++ (maybe "" (" " ++) mdesc) ++ " "
-  where
-       json = JSON.start command Nothing Nothing si
-
-showStartNothing :: String -> SeekInput -> Annex ()
-showStartNothing command si = outputMessage json $ encodeBS $
-       command ++ " "
-  where
-       json = JSON.start command Nothing Nothing si
-
 showStartMessage :: StartMessage -> Annex ()
 showStartMessage (StartMessage command ai si) = case ai of
        ActionItemAssociatedFile _ _ -> showStartActionItem command ai si
@@ -117,6 +89,20 @@ showStartMessage (CustomOutput _) =
                NormalOutput -> Annex.setOutput QuietOutput
                _ -> noop
 
+showStartActionItem :: String -> ActionItem -> SeekInput -> Annex ()
+showStartActionItem command ai si = do
+       qp <- coreQuotePath <$> Annex.getGitConfig
+       outputMessage json $
+               encodeBS command <> " " <> actionItemDesc qp ai <> " "
+  where
+       json = JSON.start command (actionItemFile ai) (actionItemKey ai) si
+
+showStartNothing :: String -> SeekInput -> Annex ()
+showStartNothing command si = outputMessage json $ encodeBS $
+       command ++ " "
+  where
+       json = JSON.start command Nothing Nothing si
+
 -- Only show end result if the StartMessage is one that gets displayed.
 showEndMessage :: StartMessage -> Bool -> Annex ()
 showEndMessage (StartMessage _ _ _) = showEndResult
index e59bd7fde87b913d1bd9ece607c812f623e9de2d..2a46cb1891607d27f63f75d30e40b99c42d6a977 100644 (file)
@@ -54,14 +54,11 @@ description of a repository. It seems that git-annex could just filter out
 control characters from all of these, since they are not filenames, and
 any control characters in them are surely malicious.
 
-Also: git-annex importfeed displays urls from the feed, and should filter
-out control characters. If such an url even can be parsed?
-
 Also: git-annex initremote with autoenable may be able to cause a remote
 with a malicious name to be set up?
 
 Also: Any place that an exception is thrown with an attacker-controlled value.
-`giveup` has been made to filter out control characters, but that leave
+`giveup` has been made to filter out control characters, but that leaves
 other exceptions, including ones thrown by libraries. Catch all exceptions
 at top-level (of program and/or worker threads) and filter out control
 characters?