Skip to content

Commit f93b38a

Browse files
committed
Return the filepaths created in "createDirStucture"
1 parent 9251483 commit f93b38a

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

bench-test-lib/src/BenchTestLib/DirIO.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module BenchTestLib.DirIO
3838
-- Imports
3939
--------------------------------------------------------------------------------
4040

41+
import Data.IORef (newIORef, modifyIORef', readIORef)
4142
import Data.Maybe (fromJust)
4243
import Data.Word (Word8)
4344
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
@@ -120,14 +121,20 @@ streamDirChunked = either Dir.readEitherChunks (const Stream.nil)
120121
-- Functions
121122
--------------------------------------------------------------------------------
122123

123-
createDirStucture :: FilePath -> Int -> Int -> IO ()
124-
createDirStucture _ depth _ | depth <= 0 = pure ()
125-
createDirStucture parentDir depth width = do
126-
for_ [1..width] $ \i -> do
127-
let iStr = show i
128-
subDir = [str|#{parentDir}/dir_#{iStr}|]
129-
createDirectoryIfMissing True subDir
130-
createDirStucture subDir (depth - 1) width
124+
createDirStucture :: FilePath -> Int -> Int -> IO [FilePath]
125+
createDirStucture root d w = do
126+
ref <- newIORef [root]
127+
createDirStucture_ ref root d w
128+
readIORef ref
129+
where
130+
createDirStucture_ _ _ depth _ | depth <= 0 = pure ()
131+
createDirStucture_ ref parentDir depth width = do
132+
for_ [1..width] $ \i -> do
133+
let iStr = show i
134+
subDir = [str|#{parentDir}/dir_#{iStr}|]
135+
createDirectoryIfMissing True subDir
136+
modifyIORef' ref (subDir:)
137+
createDirStucture_ ref subDir (depth - 1) width
131138

132139
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
133140
-- Fastest implementation, only works for posix as of now.

benchmark/Streamly/Benchmark/FileSystem/DirIO.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Main (main) where
1414
-- Imports
1515
--------------------------------------------------------------------------------
1616

17+
import Control.Monad (void)
1718
import GHC.IO.Encoding (setLocaleEncoding, utf8)
1819
import Streamly.Benchmark.Common (o_1_space_prefix)
1920

@@ -38,8 +39,8 @@ main = do
3839

3940
let smallTree = "benchmark-tmp/dir-structure-small"
4041
bigTree = "benchmark-tmp/dir-structure-big"
41-
createDirStucture smallTree 2 3
42-
createDirStucture bigTree 5 5
42+
void $ createDirStucture smallTree 2 3
43+
void $ createDirStucture bigTree 5 5
4344

4445
defaultMain
4546
[ bgroup (o_1_space_prefix moduleName)

test/Streamly/Test/FileSystem/DirIO.hs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
-- Portability : GHC
88

99
{-# LANGUAGE CPP #-}
10-
{-# LANGUAGE QuasiQuotes #-}
1110

1211
module Main (main) where
1312

@@ -17,8 +16,6 @@ module Main (main) where
1716

1817
import Data.Word (Word8)
1918
import GHC.IO.Encoding (setLocaleEncoding, utf8)
20-
import Streamly.Unicode.String (str)
21-
import System.Process (readCreateProcess, shell)
2219
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
2320
import Streamly.Data.Array (Array)
2421
#endif
@@ -72,24 +69,19 @@ main = do
7269

7370
let smallTree = "benchmark-tmp/dir-structure-small"
7471
bigTree = "benchmark-tmp/dir-structure-big"
75-
createDirStucture smallTree 2 3
76-
createDirStucture bigTree 5 5
77-
78-
findResBig <- readCreateProcess (shell [str|find #{bigTree}|]) ""
79-
findResSmall <- readCreateProcess (shell [str|find #{smallTree}|]) ""
72+
resSmall <- createDirStucture smallTree 2 3
73+
resBig <- createDirStucture bigTree 5 5
8074

8175
strmBaseCacheSmall <-
8276
Stream.fold Fold.toList
8377
$ StreamK.toStream
8478
$ StreamK.sortBy compare
85-
$ StreamK.fromStream
86-
$ Unicode.lines Fold.toList $ Stream.fromList findResSmall
79+
$ StreamK.fromStream $ Stream.fromList resSmall
8780
strmBaseCacheBig <-
8881
Stream.fold Fold.toList
8982
$ StreamK.toStream
9083
$ StreamK.sortBy compare
91-
$ StreamK.fromStream
92-
$ Unicode.lines Fold.toList $ Stream.fromList findResBig
84+
$ StreamK.fromStream $ Stream.fromList resBig
9385
let strmBaseSmall = Stream.fromList strmBaseCacheSmall
9486
let strmBaseBig = Stream.fromList strmBaseCacheBig
9587

test/streamly-tests.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ test-suite FileSystem.DirIO
453453
buildable: False
454454
build-depends:
455455
bench-test-lib
456-
, process
457456
-- Fix this test-suite for Windows
458457
if os(windows)
459458
buildable: False

0 commit comments

Comments
 (0)