From d09b01ade5dda60824758f19ee279016d107cd37 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Thu, 10 Nov 2022 22:10:49 -0600 Subject: [PATCH] Fixed archive output bug --- Makefile | 2 ++ src/stuffy.c | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a4695d0..1091a04 100644 --- a/Makefile +++ b/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 diff --git a/src/stuffy.c b/src/stuffy.c index 35c7a8f..163f179 100644 --- a/src/stuffy.c +++ b/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; }