add .propellor suffix to managed containers

Avoids deleting any containers that we don't manage..
This commit is contained in:
Joey Hess 2014-04-01 23:33:06 -04:00
parent b6ef135aa7
commit 3cc57e7fba
1 changed files with 14 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import Utility.Path
import Control.Concurrent.Async import Control.Concurrent.Async
import System.Posix.Directory import System.Posix.Directory
import Data.List
-- | Configures docker with an authentication file, so that images can be -- | Configures docker with an authentication file, so that images can be
-- pushed to index.docker.io. -- pushed to index.docker.io.
@ -177,13 +178,21 @@ ident2id :: ContainerIdent -> ContainerId
ident2id (ContainerIdent _ hn cn _) = ContainerId hn cn ident2id (ContainerIdent _ hn cn _) = ContainerId hn cn
toContainerId :: String -> Maybe ContainerId toContainerId :: String -> Maybe ContainerId
toContainerId s = case separate (== '.') s of toContainerId s
(cn, hn) | myContainerSuffix `isSuffixOf` s = case separate (== '.') (desuffix s) of
| null hn || null cn -> Nothing (cn, hn)
| otherwise -> Just $ ContainerId hn cn | null hn || null cn -> Nothing
| otherwise -> Just $ ContainerId hn cn
| otherwise = Nothing
where
desuffix = reverse . drop len . reverse
len = length myContainerSuffix
fromContainerId :: ContainerId -> String fromContainerId :: ContainerId -> String
fromContainerId (ContainerId hn cn) = cn++"."++hn fromContainerId (ContainerId hn cn) = cn++"."++hn++myContainerSuffix
myContainerSuffix :: String
myContainerSuffix = ".propellor"
containerFrom :: Image -> [Containerized Property] -> Container containerFrom :: Image -> [Containerized Property] -> Container
containerFrom = Container containerFrom = Container