Skip to content

Commit

Permalink
Fix inherit compression bug. #525
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Jul 11, 2024
1 parent 64759bd commit 62b8fb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libnffile/nffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ static int WriteAppendix(nffile_t *nffile) {
} // End of WriteAppendix

nffile_t *NewFile(nffile_t *nffile) {
int compression = 0;
int encryption = 0;
// Create struct
if (!nffile) {
nffile = calloc(1, sizeof(nffile_t));
Expand Down Expand Up @@ -687,11 +689,16 @@ nffile_t *NewFile(nffile_t *nffile) {
return NULL;
}
queue_close(nffile->processQueue);
} else {
compression = nffile->file_header->compression;
encryption = nffile->file_header->encryption;
}

memset((void *)nffile->file_header, 0, sizeof(fileHeaderV2_t));
nffile->file_header->magic = MAGIC;
nffile->file_header->version = LAYOUT_VERSION_2;
nffile->file_header->compression = compression;
nffile->file_header->encryption = encryption;

nffile->fd = 0;
nffile->compat16 = 0;
Expand Down Expand Up @@ -932,7 +939,6 @@ nffile_t *OpenNewFile(char *filename, nffile_t *nffile, int creator, int compres
nffile->fd = fd;
nffile->fileName = strdup(filename);

memset((void *)nffile->file_header, 0, sizeof(fileHeaderV2_t));
nffile->file_header->magic = MAGIC;
nffile->file_header->version = LAYOUT_VERSION_2;
nffile->file_header->nfdversion = NFDVERSION;
Expand All @@ -946,6 +952,8 @@ nffile_t *OpenNewFile(char *filename, nffile_t *nffile, int creator, int compres
nffile->file_header->encryption = encryption;
}

dbg_printf("OpenNewFile compression: %d, level: %d\n", nffile->file_header->compression, nffile->compression_level);

if (write(nffile->fd, (void *)nffile->file_header, sizeof(fileHeaderV2_t)) < sizeof(fileHeaderV2_t)) {
LogError("write() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno));
close(nffile->fd);
Expand Down

0 comments on commit 62b8fb1

Please sign in to comment.