moduleSystem.Directory.Internal.CommonwhereimportPrelude()importSystem.Directory.Internal.Prelude importSystem.FilePath((</>),isPathSeparator,isRelative,pathSeparator,splitDrive,takeDrive)-- | A generator with side-effects.newtypeListT m a =ListT {unListT ::m (Maybe(a ,ListT m a ))}emptyListT::Applicativem =>ListT m a emptyListT =ListT (pureNothing)maybeToListT::Applicativem =>m (Maybea )->ListT m a maybeToListT m =ListT (((\x ->(x ,emptyListT ))<$>)<$>m )listToListT::Applicativem =>[a ]->ListT m a listToListT []=emptyListT listToListT(x :xs )=ListT (pure(Just(x ,listToListT xs )))liftJoinListT::Monadm =>m (ListT m a )->ListT m a liftJoinListT m =ListT (m >>=unListT)listTHead::Functorm =>ListT m a ->m (Maybea )listTHead (ListT m )=(fst<$>)<$>m listTToList::Monadm =>ListT m a ->m [a ]listTToList (ListT m )=domx <-m casemx ofNothing->return[]Just(x ,m' )->doxs <-listTToList m' return(x :xs )andM::Monadm =>m Bool->m Bool->m BoolandM mx my =dox <-mx ifx thenmy elsereturnx sequenceWithIOErrors_::[IO()]->IO()sequenceWithIOErrors_ actions =go (Right())actions wherego::EitherIOError()->[IO()]->IO()go (Lefte )[]=ioErrore go(Right())[]=pure()gos (m :ms )=s `seq`dor <-tryIOErrorm go (thenEither s r )ms -- equivalent to (*>) for Either, defined here to retain compatibility-- with base prior to 4.3thenEither::Eitherb a ->Eitherb a ->Eitherb a thenEither x @(Left_)_=x thenEither_y =y -- | Similar to 'try' but only catches a specify kind of 'IOError' as-- specified by the predicate.tryIOErrorType::(IOError->Bool)->IOa ->IO(EitherIOErrora )tryIOErrorType check action =doresult <-tryIOErroraction caseresult ofLefterr ->ifcheck err thenpure(Lefterr )elsethrowIOerr Rightval ->pure(Rightval )-- | Attempt to perform the given action, silencing any IO exception thrown by-- it.ignoreIOExceptions::IO()->IO()ignoreIOExceptions io =io `catchIOError`(\_->pure())specializeErrorString::String->(IOError->Bool)->IOa ->IOa specializeErrorString str errType action =domx <-tryIOErrorType errType action casemx ofLefte ->throwIO(ioeSetErrorStringe str )Rightx ->purex ioeAddLocation::IOError->String->IOErrorioeAddLocation e loc =doioeSetLocatione newLoc wherenewLoc =loc <>ifnulloldLoc then""else":"<>oldLoc oldLoc =ioeGetLocatione dataFileType =File |SymbolicLink -- ^ POSIX: either file or directory link; Windows: file link|Directory |DirectoryLink -- ^ Windows only: directory linkderiving(Bounded,Enum,Eq,Ord,Read,Show)-- | Check whether the given 'FileType' is considered a directory by the-- operating system. This affects the choice of certain functions-- e.g. `removeDirectory` vs `removeFile`.fileTypeIsDirectory::FileType ->BoolfileTypeIsDirectory Directory =TruefileTypeIsDirectoryDirectoryLink =TruefileTypeIsDirectory_=False-- | Return whether the given 'FileType' is a link.fileTypeIsLink::FileType ->BoolfileTypeIsLink SymbolicLink =TruefileTypeIsLinkDirectoryLink =TruefileTypeIsLink_=FalsedataPermissions =Permissions {readable ::Bool,writable ::Bool,executable ::Bool,searchable ::Bool}deriving(Eq,Ord,Read,Show)-- | Convert a path into an absolute path. If the given path is relative, the-- current directory is prepended. If the path is already absolute, the path-- is returned unchanged. The function preserves the presence or absence of-- the trailing path separator.---- If the path is already absolute, the operation never fails. Otherwise, the-- operation may fail with the same exceptions as 'getCurrentDirectory'.---- (internal API)prependCurrentDirectoryWith::IOFilePath->FilePath->IOFilePathprependCurrentDirectoryWith getCurrentDirectory path =((`ioeAddLocation `"prependCurrentDirectory").(`ioeSetFileName`path ))`modifyIOError`doifisRelativepath -- avoid the call to `getCurrentDirectory` if we canthendocwd <-getCurrentDirectory letcurDrive =takeWhile(not.isPathSeparator)(takeDrivecwd )let(drive ,subpath )=splitDrivepath -- handle drive-relative paths (Windows only)pure.(</>subpath )$casedrive of_:_|(toUpper<$>drive )/=(toUpper<$>curDrive )->drive <>[pathSeparator]_->cwd elsepurepath -- | Truncate the destination file and then copy the contents of the source-- file to the destination file. If the destination file already exists, its-- attributes shall remain unchanged. Otherwise, its attributes are reset to-- the defaults.copyFileContents::FilePath-- ^ Source filename->FilePath-- ^ Destination filename->IO()copyFileContents fromFPath toFPath =(`ioeAddLocation `"copyFileContents")`modifyIOError`dowithBinaryFiletoFPath WriteMode$\hTo ->copyFileToHandle fromFPath hTo -- | Copy all data from a file to a handle.copyFileToHandle::FilePath-- ^ Source file->Handle-- ^ Destination handle->IO()copyFileToHandle fromFPath hTo =(`ioeAddLocation `"copyFileToHandle")`modifyIOError`dowithBinaryFilefromFPath ReadMode$\hFrom ->copyHandleData hFrom hTo -- | Copy data from one handle to another until end of file.copyHandleData::Handle-- ^ Source handle->Handle-- ^ Destination handle->IO()copyHandleData hFrom hTo =(`ioeAddLocation `"copyData")`modifyIOError`doallocaBytesbufferSize go wherebufferSize =131072-- 128 KiB, as coreutils `cp` uses as of May 2014 (see ioblksize.h)go buffer =docount <-hGetBufhFrom buffer bufferSize when(count >0)$dohPutBufhTo buffer count go buffer -- | Special directories for storing user-specific application data,-- configuration, and cache files, as specified by the-- <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification>.---- Note: On Windows, 'XdgData' and 'XdgConfig' map to the same directory.---- @since 1.2.3.0dataXdgDirectory =XdgData -- ^ For data files (e.g. images).-- Defaults to @~\/.local\/share@ and can be-- overridden by the @XDG_DATA_HOME@ environment variable.-- On Windows, it is @%APPDATA%@-- (e.g. @C:\/Users\//\<user\>/\/AppData\/Roaming@).-- Can be considered as the user-specific equivalent of @\/usr\/share@.|XdgConfig -- ^ For configuration files.-- Defaults to @~\/.config@ and can be-- overridden by the @XDG_CONFIG_HOME@ environment variable.-- On Windows, it is @%APPDATA%@-- (e.g. @C:\/Users\//\<user\>/\/AppData\/Roaming@).-- Can be considered as the user-specific equivalent of @\/etc@.|XdgCache -- ^ For non-essential files (e.g. cache).-- Defaults to @~\/.cache@ and can be-- overridden by the @XDG_CACHE_HOME@ environment variable.-- On Windows, it is @%LOCALAPPDATA%@-- (e.g. @C:\/Users\//\<user\>/\/AppData\/Local@).-- Can be considered as the user-specific equivalent of @\/var\/cache@.deriving(Bounded,Enum,Eq,Ord,Read,Show)-- | Search paths for various application data, as specified by the-- <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification>.---- Note: On Windows, 'XdgDataDirs' and 'XdgConfigDirs' yield the same result.---- @since 1.3.2.0dataXdgDirectoryList =XdgDataDirs -- ^ For data files (e.g. images).-- Defaults to @/usr/local/share/@ and @/usr/share/@ and can be-- overridden by the @XDG_DATA_DIRS@ environment variable.-- On Windows, it is @%PROGRAMDATA%@ or @%ALLUSERSPROFILE%@-- (e.g. @C:\/ProgramData@).|XdgConfigDirs -- ^ For configuration files.-- Defaults to @/etc/xdg@ and can be-- overridden by the @XDG_CONFIG_DIRS@ environment variable.-- On Windows, it is @%PROGRAMDATA%@ or @%ALLUSERSPROFILE%@-- (e.g. @C:\/ProgramData@).deriving(Bounded,Enum,Eq,Ord,Read,Show)

AltStyle によって変換されたページ (->オリジナル) /