From fb4384d8f7cb94d0ec3bf6b3255ccaa4fa066bcc Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 24 Nov 2009 12:58:03 +0000 Subject: added file size parameter to script execution diff --git a/newfile.sh b/newfile.sh index f4bd2e4..e388c4a 100755 --- a/newfile.sh +++ b/newfile.sh @@ -2,12 +2,13 @@ DIR=$1 FILENAME=$2 +SIZE=$3 if [ -z "$FILENAME" ]; then exit 1; fi -echo "new file detected $DIR/$FILENAME" >> /tmp/newfile.log +echo "new file of size $SIZE detected: $DIR/$FILENAME" >> /tmp/newfile.log sleep 5 rm -f $DIR/$FILENAME >> /tmp/newfile.log 2>&1 diff --git a/rhdropbox.c b/rhdropbox.c index 8403ae7..aca0cfb 100644 --- a/rhdropbox.c +++ b/rhdropbox.c @@ -37,6 +37,10 @@ #include "utils.h" #include "sysexec.h" +#include +#include +#include + enum cmd_id_enum { ADD, REMOVE, STATUS, LOG, LISTEN }; typedef enum cmd_id_enum cmd_id_t; @@ -94,11 +98,21 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst log_printf(DEBUG, "ignoring inotify_rm_watch based events"); } else { - char* const argv[] = { opt->script_, path, event->len > 0 ? event->name : "", NULL }; + struct stat stat_buf; + char buf[1024]; + snprintf(buf, 1024, "%s/%s", path, event->len > 0 ? event->name : ""); + int err = stat(buf, &stat_buf); + if(err < 0) { + log_printf(WARNING, "error at stat() for file %s", buf); + buf[0] = 0; + } + else + snprintf(buf, 1024, "%lu", stat_buf.st_size); + + char* const argv[] = { opt->script_, path, event->len > 0 ? event->name : "", buf, NULL }; char* const evp[] = { NULL }; rh_exec(opt->script_, argv, evp, child_lst); - char buf[100]; snprintf(buf, 100, "new file in '%s', name='%s'", path, event->len > 0 ? event->name : ""); log_printf(NOTICE, "%s, executed script %s", buf, opt->script_); client_t* client; -- cgit v0.10.2