From e5f1c7d9bcf618c3d1351fb006699285402f42d5 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sat, 23 Mar 2019 07:39:01 -0400 Subject: [PATCH] Fine-grain NarEffects to the perms we care about. --- hnix-store-core/src/System/Nix/Internal/Nar.hs | 17 +++++------------ hnix-store-core/tests/NarFormat.hs | 10 +++++++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/hnix-store-core/src/System/Nix/Internal/Nar.hs b/hnix-store-core/src/System/Nix/Internal/Nar.hs index 4472a96..e21e4d7 100644 --- a/hnix-store-core/src/System/Nix/Internal/Nar.hs +++ b/hnix-store-core/src/System/Nix/Internal/Nar.hs @@ -36,12 +36,11 @@ type RawFilePath = BS.ByteString data NarEffects (m :: * -> *) = NarEffects { narReadFile :: RawFilePath -> m BSL.ByteString - , narWriteFile :: RawFilePath -> BSL.ByteString -> m () + , narWriteFile :: RawFilePath -> IsExecutable -> BSL.ByteString -> m () , narListDir :: RawFilePath -> m [FilePathPart] , narCreateDir :: RawFilePath -> m () , narCreateLink :: RawFilePath -> RawFilePath -> m () - , narGetPerms :: RawFilePath -> m Permissions - , narSetPerms :: RawFilePath -> Permissions -> m () + , narIsExec :: RawFilePath -> m IsExecutable , narIsDir :: RawFilePath -> m Bool , narIsSymLink :: RawFilePath -> m Bool , narFileSize :: RawFilePath -> m Int64 @@ -214,10 +213,8 @@ localUnpackNar effs basePath (Nar fso) = localUnpackFSO basePath fso localUnpackFSO basePath fso = case fso of - Regular isExec _ bs -> do - (narWriteFile effs) basePath bs - p <- narGetPerms effs basePath - (narSetPerms effs) basePath (p {executable = isExec == Executable}) + Regular isExec _ bs -> + (narWriteFile effs) basePath isExec bs SymLink targ -> narCreateLink effs targ basePath @@ -237,14 +234,10 @@ localPackNar effs basePath = Nar <$> localPackFSO basePath fType <- (,) <$> narIsDir effs path' <*> narIsSymLink effs path' case fType of (_, True) -> SymLink <$> narReadLink effs path' - (False, _) -> Regular <$> isExecutable effs path' + (False, _) -> Regular <$> narIsExec effs path' <*> narFileSize effs path' <*> narReadFile effs path' (True , _) -> fmap (Directory . Map.fromList) $ do fs <- narListDir effs path' forM fs $ \fp -> (fp,) <$> localPackFSO (BSC.concat [path', "/", unFilePathPart fp]) - -isExecutable :: Functor m => NarEffects m -> RawFilePath -> m IsExecutable -isExecutable effs fp = - bool NonExecutable Executable . executable <$> narGetPerms effs fp diff --git a/hnix-store-core/tests/NarFormat.hs b/hnix-store-core/tests/NarFormat.hs index 45473f9..eaa4359 100644 --- a/hnix-store-core/tests/NarFormat.hs +++ b/hnix-store-core/tests/NarFormat.hs @@ -36,17 +36,21 @@ import System.Nix.Nar import System.Posix.Files (createSymbolicLink, fileSize, getFileStatus, isDirectory, readSymbolicLink) import System.Directory +import Data.Bool (bool) -- TODO: Move this to a unix-backed effects library narEffectsIO :: NarEffects IO narEffectsIO = NarEffects { narReadFile = BSL.readFile . BSC.unpack - , narWriteFile = BSL.writeFile . BSC.unpack + , narWriteFile = \f e c -> do + let f' = BSC.unpack f + BSL.writeFile f' c + p <- getPermissions f' + setPermissions f' (p { executable = e == Executable}) , narListDir = (fmap (map (FilePathPart . BSC.pack))) . listDirectory . BSC.unpack , narCreateDir = createDirectory . BSC.unpack , narCreateLink = (. BSC.unpack) . createSymbolicLink . BSC.unpack - , narGetPerms = getPermissions . BSC.unpack - , narSetPerms = setPermissions . BSC.unpack + , narIsExec = (fmap (bool NonExecutable Executable . executable)) . getPermissions . BSC.unpack , narIsDir = fmap isDirectory <$> getFileStatus . BSC.unpack , narIsSymLink = pathIsSymbolicLink . BSC.unpack , narFileSize = fmap (fromIntegral . fileSize) <$> getFileStatus . BSC.unpack