Menu

#4 Get transparent time (create/modify) stats

open
nobody
None
5
2011-03-12
2011-03-12
Mick P.
No

Do the files in the repo here have anything on the ones available via the website?

I need to extract some files from the archive whenever they are newer than some counterparts elsewhere.

Would be helpful to be able to get time stats where stats for any file in a archive would return times for that archive.

Maybe zzip_fstat could be expanded?

PS: Thanks for the library. I was shocked to find so few offerings zip archive wise.

Discussion

  • Mick P.

    Mick P. - 2011-03-12

    FYI: Anyone reading. Adding this functionality is pretty simple.

    Add the following in zzip.h

    struct zzip_dirent
    {
    int d_compr; /* compression method */
    int d_csize; /* compressed size */
    int st_size; /* file size / decompressed size */
    char * d_name; /* file name / strdupped name */

    + time_t st_atime;
    + time_t st_ctime;
    + time_t st_mtime;
    };

    And in stat.c

    int
    zzip_fstat(ZZIP_FILE * file, ZZIP_STAT * zs)
    {
    if (ZZIP_file_real(file))
    {
    struct stat st;
    if (fstat(file->fd, &st) < 0)
    return -1;
    zs->st_size = st.st_size;
    zs->d_csize = st.st_size;
    zs->d_compr = 0;

    + zs->st_atime = st.st_atime;
    + zs->st_ctime = st.st_ctime;
    + zs->st_mtime = st.st_mtime;

    return 0;
    } else
    {
    return zzip_file_stat(file, zs);
    }
    }

    Disclaimer: can't say this covers all bases. But looks good for calling zzip_fstat.

    Looks portable.

     
  • Mick P.

    Mick P. - 2011-03-12

    ^No, sorry, this is only good for "real" files.

    Since deleting the comment won't work. I will follow up soon with the solution for archived files as well (jumped the gun)

     
  • Mick P.

    Mick P. - 2011-03-20

    ^Though this is certainty doable, in lieu of testing, and because pointing out the necessary changes would be unnecessarily drawn out, I will go ahead and leave this as an exercise for whoever.

    In our case, it was decided, rather than modifying the library, better to just add some custom handling on the front end to figure out if a folder was a zip or not, and store the time if so, and store 0 if not. This was sufficient because we know where the zip files are supposed to be and there are a relative few of them to keep track of.

     
  • Mick P.

    Mick P. - 2011-03-20

    ^Though this is certainty doable, in lieu of testing, and because pointing out the necessary changes would be unnecessarily drawn out, I will go ahead and leave this as an exercise for whoever.

    In our case, it was decided, rather than modifying the library, better to just add some custom handling on the front end to figure out if a folder was a zip or not, and store the time if so, and store 0 if not. This was sufficient because we know where the zip files are supposed to be and there are a relative few of them to keep track of.

     

Log in to post a comment.