Skip to content

Commit

Permalink
Create the script file before calling it
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Feb 18, 2025
1 parent bbcbe32 commit 09bbb32
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
42 changes: 0 additions & 42 deletions bench-test-lib/create_dir_structure.sh

This file was deleted.

50 changes: 49 additions & 1 deletion bench-test-lib/src/BenchTestLib/DirIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,60 @@ streamDirChunked = either Dir.readEitherChunks (const Stream.nil)
-- Functions
--------------------------------------------------------------------------------

createDirStructureSh :: String
createDirStructureSh = [str|
#!/bin/bash

# Function to create directory structure
create_structure() {
local parent_dir=$1
local depth=$2
local width=$3

# Stop if depth reaches zero
if [ "$depth" -le 0 ]; then
return
fi

# Create subdirectories
for i in $(seq 1 "$width"); do
sub_dir="${parent_dir}/dir_$i"
mkdir -p "$sub_dir"

# Recursively create deeper levels
create_structure "$sub_dir" $((depth - 1)) "$width"
done
}

# Usage check
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <root_directory> <depth> <width>"
exit 1
fi

# Get parameters
ROOT_DIR=$1
DEPTH=$2
WIDTH=$3

# Ensure the root directory exists
mkdir -p "$ROOT_DIR"
echo "Root directory: $ROOT_DIR"

# Start creating the directory structure
create_structure "$ROOT_DIR" "$DEPTH" "$WIDTH"

echo "Directory structure creation completed."
|]

createDirStucture :: FilePath -> Int -> Int -> IO ()
createDirStucture dirRoot depth width = do
let dStr = show depth
wStr = show width
cmd =
[str|./bench-test-lib/create_dir_structure.sh #{dirRoot} #{dStr} #{wStr}|]
[str|./create_dir_structure.sh #{dirRoot} #{dStr} #{wStr}|]
writeFile "create_dir_structure.sh" createDirStructureSh
callCommand ("chmod +x create_dir_structure.sh")
callCommand ("mkdir -p " ++ dirRoot)
callCommand cmd

Expand Down
1 change: 0 additions & 1 deletion streamly.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ stability: Stable
build-type: Configure

extra-source-files:
bench-test-lib/create_dir_structure.sh
bench-test-lib/bench-test-lib.cabal
bench-test-lib/src/BenchTestLib/DirIO.hs
benchmark/*.hs
Expand Down

0 comments on commit 09bbb32

Please sign in to comment.