diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-06-12 00:31:12 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-06-12 00:31:12 +0530 |
| commit | 7ce10257856a255770c856538b4079e2b4f82bb6 (patch) | |
| tree | 3da32a1f40a0a978f56f398a00393f09aa6ef9be /lib | |
| parent | 5d216ac19a99ebb6bc0506a5745e6c3dc1dffe5e (diff) | |
| download | daffm-7ce10257856a255770c856538b4079e2b4f82bb6.tar.gz daffm-7ce10257856a255770c856538b4079e2b4f82bb6.zip | |
Fix path loading in state
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Daffm/State.hs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/Daffm/State.hs b/lib/Daffm/State.hs index f7c8aa1..fca72b6 100644 --- a/lib/Daffm/State.hs +++ b/lib/Daffm/State.hs @@ -70,11 +70,6 @@ normalizePath (Text.stripPrefix "~/" -> (Just rest)) = do pure . Text.pack . joinPath $ [home, Text.unpack rest] normalizePath dir = Text.pack <$> makeAbsolute (Text.unpack dir) -withCwdFallback :: FilePathText -> IO (Bool, FilePathText) -withCwdFallback path = do - exists <- doesPathExist $ Text.unpack path - if exists then pure (True, path) else (False,) . Text.pack <$> getCurrentDirectory - stripQuotes :: Text.Text -> Text.Text stripQuotes txt = fromMaybe txt (double <|> single) where @@ -90,12 +85,14 @@ textAsString f = Text.pack . f . Text.unpack loadDirToState :: FilePathText -> AppState -> IO AppState loadDirToState dir' appState@(AppState {stateCwd, stateListPositionHistory}) = do - (pathExists, normalizedDir) <- (normalizePath . stripTrailingSlash . stripQuotes . trim) dir' >>= withCwdFallback - stat <- Posix.getFileStatus $ Text.unpack normalizedDir + normalizedPath <- (normalizePath . stripTrailingSlash . stripQuotes . trim) dir' + pathExists <- doesPathExist $ Text.unpack normalizedPath + dirPath <- if pathExists then pure normalizedPath else Text.pack <$> getCurrentDirectory + stat <- Posix.getFileStatus $ Text.unpack dirPath let (dir, targetFilePath) = if Posix.isDirectory stat - then (normalizedDir, Nothing) - else (textAsString takeDirectory normalizedDir, Just normalizedDir) + then (dirPath, Nothing) + else (textAsString takeDirectory dirPath, Just dirPath) isReadable <- readable <$> getPermissions (Text.unpack dir) if isReadable then do |
