Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.PosixCompat.Files.setFileTimes fails on windows #119

Closed
akonsu opened this issue Aug 31, 2011 · 3 comments
Closed

System.PosixCompat.Files.setFileTimes fails on windows #119

akonsu opened this issue Aug 31, 2011 · 3 comments

Comments

@akonsu
Copy link

akonsu commented Aug 31, 2011

on windows XP the following code throws an exception:

import Control.Exception (SomeException, try)
import qualified System.Posix.Types
import System.PosixCompat.Files (accessTime, modificationTime, getFileStatus, setFileTimes)

main = do let path = "some\\file"
          (access, mod) <- getFileStatus' path
          setFileTimes path access (mod - 1)
          return ()

getFileStatus' :: FilePath -> IO (System.Posix.Types.EpochTime, System.Posix.Types.EpochTime)
getFileStatus' fp = do
    efs <- try' $ getFileStatus fp
    case efs of
        Left _ -> return (0, 0)
        Right fs -> return (accessTime fs, modificationTime fs)

try' :: IO x -> IO (Either SomeException x)
try' = try

the exception:

System.PosixCompat.Files.setFileTimes: not supported: illegal operation.

because of that yesod devel does not reload the application when a file is modified.

@luite
Copy link
Member

luite commented Aug 31, 2011

Thanks for reporting.

Apparently this operation isn't supported by unix-compat at all ( http://hdiff.luite.com/cgit/unix-compat/tree/src/System/PosixCompat/Files.hsc#n394 ). Windows does have an API function for this: http://msdn.microsoft.com/en-us/library/ms724933(v=vs.85).aspx , but there might be some problem making it compatible with the unix function (otherwise I have no idea why this wouldn't be implemented).

I personally think it's really annoying that yesod devel changes modification times for files that might be open in the user's editor, so maybe it's good to change the behaviour anyway, some ideas:

  1. copy all source and template files to a temporary directory, build the package from there. when a file is modified, just copy the file and all the files that depend on it again, and rebuild.
  2. don't build packages but use the GHC API to compile and reload files when required

1 is obviously much easier to implement, 2 is probably better in the end, since, if implemented properly, it can make recompilation much faster, but it will likely have more problems or compatibility issues than 1. Maybe 1 can be implemented first and 2 can be added later? any thoughts?

@luite
Copy link
Member

luite commented Aug 31, 2011

A little update: I'm working on an updated yesod devel that doesn't touch user files from the user anymore. It copies all .hs files to dist/src-devel and builds from there (other files don't need to be copied). A major disadvantage is that it requires some changes to the .cabal file, so existing scaffolds need to be updated

@luite
Copy link
Member

luite commented Sep 2, 2011

If you want, you can try the updated yesod devel in the new-devel branch. I've updated it to use a different method to force recompiles, which doesn't rely on setFileTimes anymore. It's not completely finished (restarting the program after a change should be improved), but it should work on Windows now.

Leave a comment if you still have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants