Compress function closer...

This commit is contained in:
Pentium44 2021-04-09 15:37:38 -07:00
parent 8664709259
commit 19012d6e66

View File

@ -98,14 +98,11 @@ char *process_line(char *line)
/* Compression function of tar */
else if(strncmp("compress",tok_srch,8) == 0)
{
char filename[MAX_FILENAME_LEN+1];
char *files[MAX_FILENAME_LEN+1];
char files[2][MAX_FILENAME_LEN+1]; // Files to be added into the archive
struct tar_t *archive = NULL;
int fd;
bzero(filename, MAX_FILENAME_LEN);
*filename = '\0';
bzero(files[0], MAX_FILENAME_LEN);
tok_srch = strtok(NULL, "\"");
if(tok_srch == NULL)
@ -120,16 +117,9 @@ char *process_line(char *line)
return NULL;
}
tok_srch = strtok(NULL, "\"");
if(tok_srch == NULL)
{
syn_warn("ss:warn:compress syntax error, missing quote?");
return NULL;
}
if(strlen(parse_vars(tok_srch)) < MAX_FILENAME_LEN)
{
strcat(files, parse_vars(tok_srch));
sprintf(files[0], "%s", parse_vars(tok_srch));
}
else
{
@ -137,7 +127,7 @@ char *process_line(char *line)
return NULL;
}
if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) == -1){
if ((fd = open(files[0], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) == -1){
syn_warn("ss:warn:compress, failed to open new archive");
return NULL;
}
@ -149,6 +139,13 @@ char *process_line(char *line)
return NULL;
}
tok_srch = strtok(NULL, "\"");
if(tok_srch == NULL)
{
syn_warn("ss:warn:compress syntax error, missing quote?");
return NULL;
}
if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0)
{
syn_warn("ss:warn:compress, missing file path (what are we gonna compress?)");
@ -163,7 +160,7 @@ char *process_line(char *line)
if(strlen(parse_vars(tok_srch)) < MAX_FILENAME_LEN)
{
strcat(files[0], parse_vars(tok_srch));
sprintf(files[1], "%s", parse_vars(tok_srch));
}
else
{
@ -171,7 +168,11 @@ char *process_line(char *line)
return NULL;
}
if (tar_write(fd, &archive, 1, &files, '1') < 0) {
const char **tarin = (const char **) &files[1];
//printf("%s", files[0]);
if (tar_write(fd, &archive, 0, tarin, '1') < 0) {
syn_warn("ss:warn:compress, failed to create archive");
return NULL;
}