Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created January 9, 2012 04:13
Show Gist options
  • Select an option

  • Save wavewave/1581044 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/1581044 to your computer and use it in GitHub Desktop.
script for change absolute link to relative link
module Main where
import Control.Concurrent
import Control.Monad
import Data.UUID
import System.Directory
import System.FilePath
import System.Process
import System.Posix.Files
main :: IO ()
main = do
putStrLn "changing absolute link to relative link"
cdir <- getCurrentDirectory
lst <- getDirectoryContents cdir
mapM_ scriptaction . map fromString $ lst
scriptaction :: Maybe UUID -> IO ()
scriptaction =
maybe (return ()) $ \uuid -> do
let str = toString uuid
odir <- getCurrentDirectory
let ndir = odir </> str </> "v0" </> "page"
doesDirectoryExist ndir >>= \b -> when b $ do
setCurrentDirectory ndir
lst <- return . filter isSVG =<< getDirectoryContents ndir
putStrLn (str ++ ": " )
mapM_ lnaction lst
setCurrentDirectory odir
isSVG :: FilePath -> Bool
isSVG fp = takeExtension fp == ".svg"
lnaction :: FilePath -> IO ()
lnaction fp = do
lfp <- readSymbolicLink fp
putStrLn $ fp ++ " -> " ++ lfp
let fn = takeFileName lfp
putStrLn $ "filename = " ++ fn
removeLink fp
threadDelay 100000
system $ "ln -s ../data/" ++ fn ++ " " ++ fp
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment