Fixed archive output bug
This commit is contained in:
parent
df97ff36d9
commit
d09b01ade5
2
Makefile
2
Makefile
@ -15,11 +15,13 @@ test: testCompile testLink testExec
|
||||
|
||||
testCompile:
|
||||
gcc $(INC) $(UNITY) -g -c -o build/unity.o $(UNITYPATH)/unity.c
|
||||
gcc $(INC) -c -o build/main.o src/main.c
|
||||
gcc $(INC) -g -c -o build/stuffy.o src/stuffy.c
|
||||
gcc $(INC) -g -c -o build/test.o test/test.c
|
||||
|
||||
testLink:
|
||||
gcc -g -o bin/test.out build/stuffy.o build/test.o build/unity.o
|
||||
gcc -o bin/stuffy.out build/stuffy.o build/main.o
|
||||
|
||||
testExec:
|
||||
./bin/test.out
|
||||
|
21
src/stuffy.c
21
src/stuffy.c
@ -106,6 +106,7 @@ void StuffyAction(char* argv[], int archiveAction)
|
||||
ListArchive(argv[2]);
|
||||
if (archiveAction == 3)
|
||||
ExtractArchive(argv);
|
||||
return;
|
||||
}
|
||||
|
||||
// Checks if filename is found in a header of archive
|
||||
@ -138,8 +139,17 @@ int IsFileArchived(char* archiveName, char* filename)
|
||||
// file already inside the archive
|
||||
void AddToArchive(char* archiveName, char* filename)
|
||||
{
|
||||
SafetyCheck(IsFileArchived(archiveName, filename),
|
||||
"File already exists in archive, try removing file first.");
|
||||
char* filenameCleaned = StripFilename(filename);
|
||||
if (IsFileArchived(archiveName, filenameCleaned))
|
||||
{
|
||||
printf("File already exists in archive, try removing file first.");
|
||||
return;
|
||||
}
|
||||
if (access(filename, F_OK))
|
||||
{
|
||||
printf("%s not found.", filename);
|
||||
return;
|
||||
}
|
||||
int archiveFile = open(archiveName, O_RDWR | O_CREAT, 0644);
|
||||
SafetyCheck((archiveFile < 0), "Archive failed to open.");
|
||||
ssize_t readSize;
|
||||
@ -147,7 +157,6 @@ void AddToArchive(char* archiveName, char* filename)
|
||||
do
|
||||
readSize = ReadSingleModule(archiveFile, &(module));
|
||||
while (readSize > 0);
|
||||
char* filenameCleaned = StripFilename(filename);
|
||||
strcpy(module.moduleHeader.moduleName, filenameCleaned);
|
||||
stat(filename, &(module.moduleHeader.moduleInfo));
|
||||
WriteSingleModule(archiveFile, &module, filename);
|
||||
@ -195,13 +204,13 @@ void ListArchive(char* archiveName)
|
||||
ssize_t readSize;
|
||||
SafetyCheck((archiveFile < 0), "Archive failed to open.");
|
||||
ModuleStruct module;
|
||||
do
|
||||
readSize = ReadSingleModule(archiveFile, &module);
|
||||
while (readSize > 0)
|
||||
{
|
||||
readSize = ReadSingleModule(archiveFile, &module);
|
||||
printf("Name: %s | Size: %ld\n", module.moduleHeader.moduleName,
|
||||
module.moduleHeader.moduleInfo.st_size);
|
||||
readSize = ReadSingleModule(archiveFile, &module);
|
||||
}
|
||||
while (readSize > 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user