-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.c
65 lines (57 loc) · 1.36 KB
/
setup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by arniejhingran on 6/28/22.
//
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include "config-parser.h"
void createFile(char path[], unsigned num);
/**
* establishes the test directories and populates them with n files based on config
* @param num
*/
void setupTestDirectory(unsigned num){
char dirName[32];
sprintf(dirName, "testFiles-%i", num);
mkdir(dirName, 0777);
for(int i = 0; i<files; i++){
createFile(dirName, i);
}
}
/**
* creates test files in the form of .txt files
* @param path
* @param num
*/
void createFile(char path[], unsigned num){
char filename[32];
sprintf(filename, "%s/testfile%i.txt", path, num);
FILE* fileToWrite = NULL;
fileToWrite = fopen(filename, "w+");
char fileCreation[100];
sprintf(fileCreation, "dd if=/dev/random of=%s oflag=direct,sync bs=1M count=1024 2>&1", filename);
//
if(fileToWrite != NULL){
if(num<read_f){
system(fileCreation);
}
else{
fprintf(fileToWrite, "test-file-generated\n");
}
}
fclose(fileToWrite);
}
/**
* sets up n test directories
* @return
*/
int main(){
parseConfig();
mkdir("test-directory", 0777);
chdir("test-directory");
for(int i = 0; i<directories; i++){
setupTestDirectory(i);
}
}