2017-12-31 20:08:31 +00:00
|
|
|
{- path manipulation
|
|
|
|
-
|
|
|
|
- Copyright 2010-2014 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- License: BSD-2-clause
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
|
|
|
module Utility.Path.Max where
|
|
|
|
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Utility.Exception
|
|
|
|
import System.Posix.Files
|
2019-08-08 16:18:53 +00:00
|
|
|
import Data.List
|
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
2017-12-31 20:08:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{- Maximum size to use for a file in a specified directory.
|
|
|
|
-
|
|
|
|
- Many systems have a 255 byte limit to the name of a file,
|
|
|
|
- so that's taken as the max if the system has a larger limit, or has no
|
|
|
|
- limit.
|
|
|
|
-}
|
|
|
|
fileNameLengthLimit :: FilePath -> IO Int
|
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
fileNameLengthLimit _ = return 255
|
|
|
|
#else
|
|
|
|
fileNameLengthLimit dir = do
|
|
|
|
-- getPathVar can fail due to statfs(2) overflow
|
|
|
|
l <- catchDefaultIO 0 $
|
|
|
|
fromIntegral <$> getPathVar dir FileNameLimit
|
|
|
|
if l <= 0
|
|
|
|
then return 255
|
|
|
|
else return $ minimum [l, 255]
|
|
|
|
#endif
|