Skip to content

Commit

Permalink
Be explicit that fd are used only a Archive creation.
Browse files Browse the repository at this point in the history
Close opened file descriptor in test before checking equivalence.
  • Loading branch information
mgautierfr committed Feb 26, 2024
1 parent a85f4bb commit 51b1dc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/zim/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ namespace zim
/** Archive constructor.
*
* Construct an archive from a file descriptor.
* Fd is used only at Archive creation.
* Ownership of the fd is not taken and it must be closed by caller.
*
* Note: This function is not available under Windows.
*
Expand All @@ -108,6 +110,8 @@ namespace zim
*
* Construct an archive from a descriptor of a file with an embedded ZIM
* archive inside.
* Fd is used only at Archive creation.
* Ownership of the fd is not taken and it must be closed by caller.
*
* Note: This function is not available under Windows.
*
Expand All @@ -120,6 +124,8 @@ namespace zim
*
* Construct an archive from several file descriptors.
* Each part may be embedded in a file.
* Fds are used only at Archive creation.
* Ownership of the fds is not taken and they must be closed by caller.
* Fds (int) can be the same between FdInput if the parts belong to the same file.
*
* Note: This function is not available under Windows.
Expand Down
5 changes: 5 additions & 0 deletions test/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ TEST(ZimArchive, openZIMFileEmbeddedInAnotherFile)
const zim::Archive archive1(normalZims[i].path);
const int fd = OPEN_READ_ONLY(embeddedZims[i].path);
const zim::Archive archive2(zim::FdInput(fd, 8, archive1.getFilesize()));
close(fd);

checkEquivalence(archive1, archive2);
}
Expand Down Expand Up @@ -653,6 +654,10 @@ TEST(ZimArchive, openZIMFileMultiPartEmbeddedInAnotherFile)

const zim::Archive archive2(fds);

for(auto &fd: fds) {
close(fd.fd);
}

checkEquivalence(archive1, archive2);
}
}
Expand Down

0 comments on commit 51b1dc0

Please sign in to comment.