Skip to content

Commit

Permalink
unpacked: let archivers "abandon" the archive instead of closing it.
Browse files Browse the repository at this point in the history
This lets you preserve the PHYSFS_Io in case of error during archive opening.
  • Loading branch information
icculus committed Jul 21, 2017
1 parent 91a1998 commit 3c9351c
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/archiver_grp.c
Expand Up @@ -78,7 +78,7 @@ static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!grpLoadEntries(io, count, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
2 changes: 1 addition & 1 deletion src/archiver_hog.c
Expand Up @@ -77,7 +77,7 @@ static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!hogLoadEntries(io, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
2 changes: 1 addition & 1 deletion src/archiver_iso9660.c
Expand Up @@ -315,7 +315,7 @@ static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename, int forWri

if (!iso9660LoadEntries(io, joliet, "", rootpos, rootpos + len, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
2 changes: 1 addition & 1 deletion src/archiver_mvl.c
Expand Up @@ -72,7 +72,7 @@ static void *MVL_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!mvlLoadEntries(io, count, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
2 changes: 1 addition & 1 deletion src/archiver_qpak.c
Expand Up @@ -88,7 +88,7 @@ static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!qpakLoadEntries(io, count, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
2 changes: 1 addition & 1 deletion src/archiver_slb.c
Expand Up @@ -98,7 +98,7 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!slbLoadEntries(io, count, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
9 changes: 9 additions & 0 deletions src/archiver_unpacked.c
Expand Up @@ -51,6 +51,15 @@ void UNPK_closeArchive(void *opaque)
} /* if */
} /* UNPK_closeArchive */

void UNPK_abandonArchive(void *opaque)
{
UNPKinfo *info = ((UNPKinfo *) opaque);
if (info)
{
info->io = NULL;
UNPK_closeArchive(info);
} /* if */
} /* UNPK_abandonArchive */

static PHYSFS_sint64 UNPK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
{
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_wad.c
Expand Up @@ -97,7 +97,7 @@ static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

if (!wadLoadEntries(io, count, unpkarc))
{
UNPK_closeArchive(unpkarc);
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */

Expand Down
1 change: 1 addition & 0 deletions src/physfs_internal.h
Expand Up @@ -342,6 +342,7 @@ int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len);

/* These are shared between some archivers. */

void UNPK_abandonArchive(void *opaque);
void UNPK_closeArchive(void *opaque);
void *UNPK_openArchive(PHYSFS_Io *io);
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
Expand Down

0 comments on commit 3c9351c

Please sign in to comment.