Commits

Laurie Clark-Michalek committed 63174c3

Fixed a bug where spy would not accept any events when it was started in a hidden directory.

Comments (0)

Files changed (2)

 
 import System.Console.CmdArgs
 import System.Directory (canonicalizePath)
+import System.FilePath (addTrailingPathSeparator)
 import Spy.Watcher
 
 version :: String
 main = do
     config <- cmdArgsRun mode
     canonicalizedDir <- canonicalizePath $ dir config
-    spy config { dir = canonicalizedDir }
+    spy config { dir = addTrailingPathSeparator canonicalizedDir }
     putStrLn "No eyes on the target"
-

src/Spy/Watcher.hs

 import System.IO (stderr, hPrint)
 import System.FilePath.GlobPattern
 import System.FilePath (splitDirectories, takeFileName)
-import Filesystem.Path.CurrentOS (encodeString, decodeString)
+import Filesystem.Path.CurrentOS
+  (encodeString, decodeString, commonPrefix, stripPrefix)
 import Data.Time.Clock(UTCTime)
-import Data.Maybe (fromMaybe, maybeToList)
+import Data.Maybe (fromMaybe, maybeToList, fromJust)
 import Text.JSON
 
 -- | The output format when Spy prints out changes to STDOUT
 skipEvent :: Spy -> FilePath -> Bool
 skipEvent config path = skipHidden || skipNonMatchingGlob
     where skipHidden            = let includeHiddenfiles = hidden config
-                                  in not includeHiddenfiles && containsHiddenPathElement path
+                                  in not includeHiddenfiles && containsHiddenPathElement relPath
           skipNonMatchingGlob   = maybe False (not . matchesFile path) $ glob config
+          relPath = encodeString . fromJust $ stripPrefix prefix (decodeString path)
+          prefix = commonPrefix (map decodeString [(dir config), path])
 
 eventTime :: Event -> UTCTime
 eventTime (Added _ t) = t