1 % Copyright (C) 2004 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
20 module Darcs.CheckFileSystem ( can_I_use_mmap ) where
22 import System.Directory ( removeFile, removeDirectory, setCurrentDirectory,
25 import Control.Exception ( block )
27 import Darcs.Utils ( withCurrentDirectory )
28 import Darcs.Lock ( withOpenTemp )
30 -- Beware that the below test will return true in any directory where we
31 -- don't have write permission. This is risky, but means we'll do the
32 -- right thing in the common case where we're dealing with posix
33 -- filesystems and directories in which we don't have permission to write.
35 can_I_remove_open_files :: IO Bool
36 can_I_remove_open_files = block $
37 (withOpenTemp $ \ (_,f) ->
38 (do { removeFile f; return True}) `catch` \_ -> return False)
39 `catch` \_ -> return True
41 can_I_remove_directories_holding_open_files :: IO Bool
42 can_I_remove_directories_holding_open_files = block $
43 (do createDirectory "darcs_testing_for_nfs"
44 okay <- (withCurrentDirectory "darcs_testing_for_nfs" $
45 do withOpenTemp $ \ (_,f) ->
47 setCurrentDirectory ".."
48 removeDirectory "darcs_testing_for_nfs"
50 ) `catch` \_ -> return False
51 ) `catch` \_ -> return True
52 removeDirectory "darcs_testing_for_nfs" `catch` \_ -> return ()
54 ) `catch` \_ -> return True
56 can_I_use_mmap :: IO Bool
57 can_I_use_mmap = do a <- can_I_remove_open_files
58 if a then can_I_remove_directories_holding_open_files