diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-24 12:58:03 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-24 12:58:03 (GMT) |
commit | fb4384d8f7cb94d0ec3bf6b3255ccaa4fa066bcc (patch) | |
tree | 276f56b9d594a972d29b3b49d2c762365016d760 | |
parent | 402796b55322167c3fa0d33d77eafb65761e4a59 (diff) |
added file size parameter to script execution
-rwxr-xr-x | newfile.sh | 3 | ||||
-rw-r--r-- | rhdropbox.c | 18 |
2 files changed, 18 insertions, 3 deletions
@@ -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 <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + 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; |