[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl6-internals
Subject:    Re: Issues With Creating Featherspec Archives
From:       Peter Lobsinger <plobsing () gmail ! com>
Date:       2011-10-25 1:56:41
Message-ID: CAKxNnpnh1TMK+xv+G-AnVryRex3++tmvf553Q4TSd15-SHqyPw () mail ! gmail ! com
[Download RAW message or body]

On Mon, Oct 24, 2011 at 2:51 PM, Kevin Polulak <kpolulak@gmail.com> wrote:
> The problem I'm having is with recursively adding directories to an archive.
> The libzip library provides a function called zip_add_dir() that is supposed
> to do this. Unfortunately, it has no relation to the user's fileystem
> outside the archive. When you add a directory "foo", you are just creating
> an entry within the archive for a directory; you are not actually copying
> the "foo" directory from the user's filesystem. This means I have to iterate
> over the directory tree to add files. I even contacted the libzip mailing
> list and that is my only option apparently.
>
> I turned to Rosella for this and experimented with
> Rosella::FileSystem::Directory.walk(). However, it only walks through files
> and does not include directories in the resulting array so I can't do
> something like `if (is directory) { zip_add_dir() } else { zip_add() }`.
>
> Does anybody have an idea how I could fix this problem? Suggestions?

I am not experienced with libzip, but the docs do not explicitly say
you need to create directories before you put files in them. A simple
test program (attached) confirms that you don't need to do so. The one
shortcomming of this approach is that you skip empty directories, but
for some uses (including perhaps this one?), this is acceptable.

> --
> - Kevin Polulak (soh_cah_toa)
>
>
> _______________________________________________
> http://lists.parrot.org/mailman/listinfo/parrot-dev
>
>

["test.c" (text/x-csrc)]

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <zip.h>

int main(void)
{
    int err = 0;
    struct zip *zip = zip_open("test.zip", ZIP_CREATE, &err);
    if (!zip)
    {
	char buf[1024];
	zip_error_to_str(buf, sizeof(buf), errno, err);
	fprintf(stderr, buf);
	return EXIT_FAILURE;
    }

    struct zip_source *source = zip_source_file(zip, "hello.txt", 0, -1);
    if (!source)
	goto zip_error;

    if (zip_add(zip, "foo/bar.txt", source))
	goto zip_error;

    if (zip_close(zip))
	goto zip_error;

    return EXIT_SUCCESS;

  zip_error:
	fprintf(stderr, zip_strerror(zip));
	return EXIT_FAILURE;
}


_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic