-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_dirs_CWV_Leftovers.c
135 lines (107 loc) · 3.78 KB
/
make_dirs_CWV_Leftovers.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
General Notes:
Order of operations version 1:
1. extract from a tarfile
2. store this away in the mega struct
3. "expand" and make the equivalent directory by filling out with data from the mega struct.
Order of operations version 2:
1. For each tarfile make an equivalent directory.
2. extract the contents of this tarfile into this directory - this is the "expansion".
3. tar -xvf public_html-14-09-12.tar -C mkdtemp("the equivalent directory for the tar archive").
* probably using: mkdtemp().
All commands are exec with fork(), ececl() and wait():
- we need to implement the systemcalls?
we can get the size in bytes and mod time from stat() e.g:
>>> stat sample_1.tar:
>>> File: sample_1.tar
>>> Size: 10240 Blocks: 24 IO Block: 4096 regular file
>>> Device: eh/14d Inode: 13510798882194159 Links: 1
>>> Access: (0777/-rwxrwxrwx) Uid: ( 1000/fraser_p) Gid: ( 1000/fraser_p)
>>> Access: 2020-09-28 13:26:57.692909200 +0800
>>> Modify: 2020-09-28 13:26:46.969176800 +0800
>>> Change: 2020-09-28 13:26:46.969176800 +0800
* can we "parse" this like an eventfile???
*/
// General Questions:
/*
* How is the modification date displayed? and will the discrepancy between "our" -tvf and "Chris"
- is it o to use stat() for this??
*/
/*
1. char *mkdtemp(char *template);
ERRORS
EINVAL The last six characters of template were not XXXXXX. Now template is unchanged.
*/
/*
execl( "./goodchessmove", // on-disk location of program
"goodchessmove", // its argv[0]
gamestate, // its argv[1]
outputfile, // its argv[2]
NULL
);
*/
/*
This function reads in the output from tar -xvf tarfile.tar
into a unique, temporary directory.
*/
// WITHOUT FORK - EXTRAT INTO mkdirtemp():
/*
int make_an_expanded_dir(char tarfile[]) {
// this function is supposed to extract a tar archive into the result of "mkdtemp(template)"
// char *temp_dir = mkdtemp(template); // Segmentation fault (core dumped)
// the template for the temporary directory:
char template[] = "/tmp/file-XXXXXX";
// the temporary directory:
char *temp_dir = mkdtemp(template);
// the cmd line refference to the tarfile:
// printf("error 3\n");
// char *the_tarfile = strcat(tarfile, ".tar");
// this needs to be beefed up
if(temp_dir == NULL) {
perror("mkdtemp failed: ");
return 0;
}
// the location of tar is found by the cmdline thing type tar
// do we want to frok() an excel()???
execl("/usr/bin/tar",
"tar",
"-xf", // -xvf for testing!
tarfile, // this is actually tar_2.tar
"-C",
temp_dir,
NULL
);
}
*/
// WITHOUT FORK - EXTRACT INTO "NORMAL" DIRECTORY:
/*
int make_an_expanded_dir(char tarfile[]) {
// this function is supposed to extract a tar archive into the result of "mkdtemp(template)"
// char *temp_dir = mkdtemp(template); // Segmentation fault (core dumped)
// the template for the temporary directory:
printf("error 1\n");
char template[] = "/tmp/file-XXXXXX";
// the temporary directory:
printf("error 2\n");
char *temp_dir = mkdtemp(template);
// the cmd line refference to the tarfile:
// printf("error 3\n");
// char *the_tarfile = strcat(tarfile, ".tar");
// this needs to be beefed up
if(temp_dir == NULL) {
perror("mkdtemp failed: ");
return 0;
}
// the location of tar is found by the cmdline thing type tar
// do we want to frok() an excel()???
printf("before the execl()\n");
execl("/usr/bin/tar",
"tar",
"-xvf",
tarfile, // this is actually tar_2.tar
"-C",
"TARGET_DIR/",
NULL
);
}
*/