darcs-2.14.1: a distributed, interactive, smart revision control system

Darcs.Util.Path

Synopsis

# Documentation

data FileName Source #

FileName is an abstract type intended to facilitate the input and output of unicode filenames.

Instances

 Source # Methods Source # Methods(<) :: FileName -> FileName -> Bool #(>) :: FileName -> FileName -> Bool # Source # MethodsshowList :: [FileName] -> ShowS # Source # Methodsput :: FileName -> Put #putList :: [FileName] -> Put # Source # Methods Source # Methods

convert a path string into a sequence of directories strings "/", "." and ".." are generally interpreted as expected. Behaviour with too many '..' is to leave them.

Examples: Splitting: "aabbcc" -> ["aa","bb","cc"] Ignoring "." and extra "/": "aa.bb" -> ["aa","bb"] "aa//bb" -> ["aa","bb"] "aabb/" -> ["aa","bb"] Handling "..": "aa..bb/cc" -> ["bb","cc"] "aabb....cc" -> ["cc"] "aa..bb..cc" -> ["cc"] "../cc" -> ["..","cc"]

encodeWhite translates whitespace in filenames to a darcs-specific format (numerical representation according to ord surrounded by backslashes). Note that backslashes are also escaped since they are used in the encoding.

encodeWhite "hello there" == "hello\32\there"
encodeWhite "hello\there" == "hello\92\there"

decodeWhite interprets the Darcs-specific "encoded" filenames produced by encodeWhite

decodeWhite "hello\32\there"  == "hello there"
decodeWhite "hello\92\there"  == "hello\there"
decodeWhite "hello\there"   == error "malformed filename"

# AbsolutePath

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [AbsolutePath] -> ShowS # Source # Methods Source # Methods

Take an absolute path and a string representing a (possibly relative) path and combine them into an absolute path. If the second argument is already absolute, then the first argument gets ignored. This function also takes care that the result is converted to Posix convention and normalized. Also, parent directories ("..") at the front of the string argument get canceled out against trailing directory parts of the absolute path argument.

Regarding the last point, someone more familiar with how these functions are used should verify that this is indeed necessary or at least useful.

Interpret a possibly relative path wrt the current working directory.

The root directory as an absolute path.

# AbsolutePathOrStd

This is for situations where a string (e.g. a command line argument) may take the value "-" to mean stdin or stdout (which one depends on context) instead of a normal file path.

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [AbsolutePathOrStd] -> ShowS #

useAbsoluteOrStd :: (AbsolutePath -> a) -> a -> AbsolutePathOrStd -> a Source #

Execute either the first or the second argument action, depending on whether the given path is an AbsolutePath or stdin/stdout.

# AbsoluteOrRemotePath

Instances

 Source # Methods Source # Methods Source # Methods Source # Methods

# SubPath

data SubPath Source #

Paths which are relative to the local darcs repository and normalized. Note: These are understood not to have the dot in front.

Instances

 Source # Methods(==) :: SubPath -> SubPath -> Bool #(/=) :: SubPath -> SubPath -> Bool # Source # Methods(<) :: SubPath -> SubPath -> Bool #(<=) :: SubPath -> SubPath -> Bool #(>) :: SubPath -> SubPath -> Bool #(>=) :: SubPath -> SubPath -> Bool # Source # MethodsshowList :: [SubPath] -> ShowS # Source # Methods Source # Methods

Make the second path relative to the first, if possible

Transform a SubPath into an AnchoredPath.

# Miscellaneous

class FilePathOrURL a where Source #

Minimal complete definition

toPath

Methods

toPath :: a -> String Source #

Instances

 Source # Methods Source # Methods Source # Methods Source # Methods CharLike c => FilePathOrURL [c] Source # MethodstoPath :: [c] -> String Source #

class FilePathOrURL a => FilePathLike a where Source #

Minimal complete definition

toFilePath

Methods

toFilePath :: a -> FilePath Source #

Instances

 Source # Methods Source # Methods Source # Methods CharLike c => FilePathLike [c] Source # MethodstoFilePath :: [c] -> FilePath Source #

getUniquePathName :: Bool -> (FilePath -> String) -> (Int -> FilePath) -> IO FilePath Source #

Iteratively tries find first non-existing path generated by buildName, it feeds to buildName the number starting with -1. When it generates non-existing path and it isn't first, it displays the message created with buildMsg. Usually used for generation of the name like path_number when path already exist (e.g. darcs.net_0).

# Check for malicious paths

What is a malicious path?

A spoofed path is a malicious path.

1. Darcs only creates explicitly relative paths (beginning with "./"), so any not explicitly relative path is surely spoofed.
2. Darcs normalizes paths so they never contain "/../", so paths with "/../" are surely spoofed.

A path to a darcs repository's meta data can modify "trusted" patches or change safety defaults in that repository, so we check for paths containing "/_darcs/" which is the entry to darcs meta data.

To do?

• Would it be worth adding a --semi-safe-paths option for allowing changes to certain preference files (_darcs/prefs/) in sub repositories'?

TODO: Properly review the way we handle paths on Windows - it's not enough to just use the OS native concept of path separator. Windows often accepts both path separators, and repositories always use the UNIX separator anyway.

Warning : this is less rigorous than isMaliciousPath but it's to allow for subpath representations that don't start with ./

# Tree filtering.

filterFilePaths :: [FilePath] -> AnchoredPath -> t -> Bool Source #

Same as filterPath, but for ordinary FilePaths (as opposed to AnchoredPath).

filterPaths :: [AnchoredPath] -> AnchoredPath -> t -> Bool Source #

Construct a filter from a list of AnchoredPaths, that will accept any path that is either a parent or a child of any of the listed paths, and discard everything else.

# AnchoredPaths: relative paths within a Tree. All paths are

data Name Source #

Instances

 Source # Methods(==) :: Name -> Name -> Bool #(/=) :: Name -> Name -> Bool # Source # Methodscompare :: Name -> Name -> Ordering #(<) :: Name -> Name -> Bool #(<=) :: Name -> Name -> Bool #(>) :: Name -> Name -> Bool #(>=) :: Name -> Name -> Bool #max :: Name -> Name -> Name #min :: Name -> Name -> Name # Source # MethodsshowsPrec :: Int -> Name -> ShowS #show :: Name -> String #showList :: [Name] -> ShowS #

newtype AnchoredPath Source #

This is a type of "sane" file paths. These are always canonic in the sense that there are no stray slashes, no ".." components and similar. They are usually used to refer to a location within a Tree, but a relative filesystem path works just as well. These are either constructed from individual name components (using "appendPath", "catPaths" and "makeName"), or converted from a FilePath ("floatPath" -- but take care when doing that) or .

Constructors

 AnchoredPath [Name]

Instances

Append an element to the end of a path.

Take a "root" directory and an anchored path and produce a full FilePath. Moreover, you can use anchorPath "" to get a relative FilePath.

Check whether a path is a prefix of another path.

Get parent (path) of a given path. foobarbaz -> foo/bar

List all parents of a given path. foobarbaz -> [foo, foo/bar]

Catenate two paths together. Not very safe, but sometimes useful (e.g. when you are representing paths relative to a different point than a Tree root).

Append a String to the last Name of an AnchoredPath.

# Unsafe AnchoredPath functions.

Take a relative FilePath and turn it into an AnchoredPath. The operation is (relatively) unsafe. Basically, by using floatPath, you are testifying that the argument is a path relative to some common root -- i.e. the root of the associated Tree object. Also, there are certain invariants about AnchoredPath that this function tries hard to preserve, but probably cannot guarantee (i.e. this is a best-effort thing). You should sanitize any FilePaths before you declare them "good" by converting into AnchoredPath (using this function).

Take a prefix path, the changed prefix path, and a path to change. Assumes the prefix path is a valid prefix. If prefix is wrong return AnchoredPath [].