mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 20:01:59 +01:00
Fixed zip structure
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
98506d5b3a
commit
5b3161e685
@ -137,8 +137,13 @@ unsigned char *extract_file_from_zip(char *zipfile, char *filename, zip_uint64_t
|
||||
struct zip *z;
|
||||
struct zip_stat sb;
|
||||
struct zip_file *zf;
|
||||
#if LIBZIP_VERSION_MAJOR >= 1 && LIBZIP_VERSION_MINOR >= 1
|
||||
int zip_flags = ZIP_RDONLY;
|
||||
#else
|
||||
int zip_flags = 0;
|
||||
#endif
|
||||
|
||||
z = zip_open(zipfile, ZIP_RDONLY, &errorp);
|
||||
z = zip_open(zipfile, zip_flags, &errorp);
|
||||
if(!z){
|
||||
syslog(LOG_INFO, "%s: error: corrupt zip file=%s, error code=%d", zipfile, filename, errorp);
|
||||
return NULL;
|
||||
@ -183,8 +188,6 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de
|
||||
EVP_CIPHER_CTX *ctx=NULL;
|
||||
#endif
|
||||
|
||||
syslog(LOG_PRIORITY, "retrieveing %s", filename);
|
||||
|
||||
if(filename == NULL) return 1;
|
||||
|
||||
relfilename = strchr(filename, ' ');
|
||||
@ -195,6 +198,11 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de
|
||||
relfilename++;
|
||||
|
||||
zipbuf = extract_file_from_zip(filename, relfilename, &zipped_size);
|
||||
if(!zipped_size){
|
||||
syslog(LOG_PRIORITY, "%s not found in %s", relfilename, filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
len = zipped_size+EVP_MAX_BLOCK_LENGTH;
|
||||
}
|
||||
else {
|
||||
@ -300,12 +308,12 @@ void assemble_filename(char *filename, int len, char *s, struct config *cfg){
|
||||
char zipfilename[SMALLBUFSIZE];
|
||||
struct stat st;
|
||||
|
||||
snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10]);
|
||||
// /var/piler/00/5f5/00/5f5_00.zip
|
||||
snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c/%c%c/%c%c%c_%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3]);
|
||||
|
||||
if(cfg->consolidated_store == 1 && stat(zipfilename, &st) == 0){
|
||||
// If the zip file exists, then fix the filename to be '<zipfile> <relative filename>'
|
||||
snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.m",
|
||||
zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s);
|
||||
snprintf(filename, len-1, "%s %c%c/%s.m", zipfilename, s[RND_STR_LEN-2], s[RND_STR_LEN-1], s);
|
||||
}
|
||||
else {
|
||||
snprintf(filename, len-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.m",
|
||||
@ -324,11 +332,10 @@ void assemble_attachment_filename(char *filename, int len, char *s, int attachme
|
||||
char zipfilename[SMALLBUFSIZE];
|
||||
struct stat st;
|
||||
|
||||
snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10]);
|
||||
snprintf(zipfilename, sizeof(zipfilename)-1, "%s/%02x/%c%c%c/%c%c/%c%c%c_%c%c.zip", cfg->queuedir, cfg->server_id, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3]);
|
||||
|
||||
if(cfg->consolidated_store == 1 && stat(zipfilename, &st) == 0){
|
||||
snprintf(filename, len-1, "%s %c%c%c/%c%c/%c%c/%s.a%d",
|
||||
zipfilename, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id);
|
||||
snprintf(filename, len-1, "%s %c%c/%s.a%d", zipfilename, s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id);
|
||||
}
|
||||
else {
|
||||
snprintf(filename, len-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, s[8], s[9], s[10], s[RND_STR_LEN-4], s[RND_STR_LEN-3], s[RND_STR_LEN-2], s[RND_STR_LEN-1], s, attachment_id);
|
||||
|
@ -32,6 +32,7 @@ all:
|
||||
|
||||
install:
|
||||
$(INSTALL) -m 0755 $(srcdir)/automated-search.php $(DESTDIR)$(libexecdir)/piler
|
||||
$(INSTALL) -m 0755 $(srcdir)/compact-store-dir.sh $(DESTDIR)$(libexecdir)/piler
|
||||
$(INSTALL) -m 0755 $(srcdir)/daily-report.php $(DESTDIR)$(libexecdir)/piler
|
||||
$(INSTALL) -m 0755 $(srcdir)/gmail-imap-import.php $(DESTDIR)$(libexecdir)/piler
|
||||
$(INSTALL) -m 0755 $(srcdir)/generate_stats.php $(DESTDIR)$(libexecdir)/piler
|
||||
|
30
util/compact-store-dir.sh
Executable file
30
util/compact-store-dir.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT_PATH="$(readlink -f "$0")"
|
||||
SCRIPT_NAME="${SCRIPT_PATH##*/}"
|
||||
|
||||
SERVERID="00"
|
||||
|
||||
usage() {
|
||||
echo "usage: ${SCRIPT_NAME} <topdir>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
[[ $# -gt 0 ]] || usage
|
||||
|
||||
TOPDIR="$1"
|
||||
|
||||
cd "/var/piler/store/${SERVERID}"
|
||||
|
||||
for i in "$TOPDIR"/*; do
|
||||
pushd "$i" > /dev/null
|
||||
d="$(basename "$i")"
|
||||
zip -r -0 -q -m "${TOPDIR}_${d}.zip" .
|
||||
popd > /dev/null
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user