Skip to content
Permalink
Browse files

BUG+TST Fix lock1() handling of full_paths

fixes #68
  • Loading branch information...
unode committed May 17, 2018
1 parent d2e99b1 commit cd02257b6075a4399c29bdb74b882ef89cf24f19
Showing with 21 additions and 1 deletion.
  1. +10 −1 NGLess/StandardModules/Parallel.hs
  2. +11 −0 tests/parallel_folder_lock/lock.ngl
@@ -51,6 +51,7 @@ import Control.Monad.State.Lazy
import System.IO
import Data.IORef
import Data.Default
import Data.Maybe (fromMaybe)
import System.IO.Unsafe (unsafePerformIO)
import System.Directory (createDirectoryIfMissing, doesFileExist, getDirectoryContents)

@@ -110,11 +111,19 @@ setupHashDirectory basename hash = do
liftIO $ atomicWriteFile scriptfile sct
return actiondir

-- Beware that addition of characters here can lead to lock collisions
-- as is "project/sample" clashes with "project_sample" but ... uncommon case
unsafeCharMap = [('/', '_'),
('\\', '_')]

sanitizeLock :: T.Text -> T.Text
sanitizeLock = T.map (\x -> fromMaybe x (lookup x unsafeCharMap))

executeLock1 (NGOList entries) kwargs = do
entries' <- mapM (stringOrTypeError "lock1") entries
hash <- lookupStringOrScriptError "lock1" "__hash" kwargs
lockdir <- setupHashDirectory "ngless-locks" hash
(e,rk) <- getLock lockdir entries'
(e,rk) <- getLock lockdir (sanitizeLock <$> entries')
outputListLno' InfoOutput ["lock1: Obtained lock file: '", lockdir </> T.unpack e ++ ".lock", "'"]
reportbase <- setupHashDirectory "ngless-stats" hash
let reportdir = reportbase </> T.unpack e
@@ -0,0 +1,11 @@
ngless "0.8"
import "parallel" version "0.6"

samples = [
"projectA/sampleA1",
"projectB/sampleB1"
]

# Check if lock1 can handle paths containing / or \
# throws an error it can't
lock1(samples)

0 comments on commit cd02257

Please sign in to comment.
You can’t perform that action at this time.