Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant complications when writing an archiver with write support #58

Open
Torphedo opened this issue May 7, 2023 · 1 comment
Open

Comments

@Torphedo
Copy link

Torphedo commented May 7, 2023

I'm trying to write an archiver with streaming write support (a simple format covered by the unpacked template). I implemented an openWrite() function I wanted to test, but PHYSFS_openWrite() never reaches it. It fails in verifyPath() because it uses the directory archiver's stat function, determines it doesn't exist, and returns an error.

It calls DIR_stat() here, and here's an example of my source code:

const char packname[] = "Armor_012_Upper.pack";

int main(int argc, char** argv) {
    PHYSFS_init(argv[0]);
    PHYSFS_mount(PHYSFS_getBaseDir(), NULL, true);
    PHYSFS_setWriteDir(PHYSFS_getBaseDir());

    PHYSFS_registerArchiver(&archiver_sarc_default);

    printf("Mounting %s...\n\n", packname);
    PHYSFS_mount(packname, NULL, true);

    PHYSFS_file* test_write = PHYSFS_openWrite("/ActorLink/Armor_012_Upper.bxml");
    printf("%p\n", test_write);
}

I'm able to read the file into a buffer with PHYSFS_openRead() and PHYSFS_readBytes() and write it to disk (I omitted the code for this to keep the code snippet short). So the file definitely exists, and the archiver is registered correctly.

TLDR: Writing has very different behaviour from reading which seems to prevent me from even reaching the writing code in my archiver. I could try to re-implement PHYSFS_openWrite() myself, but I would prefer not to if possible.

@Torphedo
Copy link
Author

Torphedo commented May 19, 2023

Update: I fixed this by making the function search the search path for an appropriate handle instead of using the write directory in a fork. I'm still running into a ton of roadblocks trying to get write support working for a simple format, though.

I need to copy files into their own buffers for streaming writes, then rebuild it into an archive when writing is done for it to be even a little bit efficient. I could make it atomic, but I really don't want to rebuild the archive file and write it to disk on every single write. If there's some better way to implement this that doesn't require changing a lot of the PhysicsFS code, that would be great.

@Torphedo Torphedo changed the title Unable to call an archiver's openWrite function using PHYSFS_openWrite Significant complications when writing an archiver with write support May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant