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