webyesod: an edit should not error when the file path is just a filename
This commit is contained in:
parent
226ba76296
commit
39bed956d6
@ -123,13 +123,17 @@ writeFileWithBackup f t = backUpFile f >> writeFile f t
|
|||||||
-- | Back up this file with a (incrementing) numbered suffix, or give an error.
|
-- | Back up this file with a (incrementing) numbered suffix, or give an error.
|
||||||
backUpFile :: FilePath -> IO ()
|
backUpFile :: FilePath -> IO ()
|
||||||
backUpFile fp = do
|
backUpFile fp = do
|
||||||
fs <- getDirectoryContents $ takeDirectory fp
|
fs <- safeGetDirectoryContents $ takeDirectory $ fp
|
||||||
let (d,f) = splitFileName fp
|
let (d,f) = splitFileName fp
|
||||||
versions = catMaybes $ map (f `backupNumber`) fs
|
versions = catMaybes $ map (f `backupNumber`) fs
|
||||||
next = maximum (0:versions) + 1
|
next = maximum (0:versions) + 1
|
||||||
f' = printf "%s.%d" f next
|
f' = printf "%s.%d" f next
|
||||||
copyFile fp (d </> f')
|
copyFile fp (d </> f')
|
||||||
|
|
||||||
|
safeGetDirectoryContents :: FilePath -> IO [FilePath]
|
||||||
|
safeGetDirectoryContents "" = getDirectoryContents "."
|
||||||
|
safeGetDirectoryContents fp = getDirectoryContents fp
|
||||||
|
|
||||||
-- | Does the second file represent a backup of the first, and if so which version is it ?
|
-- | Does the second file represent a backup of the first, and if so which version is it ?
|
||||||
backupNumber :: FilePath -> FilePath -> Maybe Int
|
backupNumber :: FilePath -> FilePath -> Maybe Int
|
||||||
backupNumber f g = case matchRegexPR ("^" ++ f ++ "\\.([0-9]+)$") g of
|
backupNumber f g = case matchRegexPR ("^" ++ f ++ "\\.([0-9]+)$") g of
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user