From: Miloš Mulač Date: Tue, 20 Feb 2007 11:42:15 +0000 (+0000) Subject: tar file exclude data read part optimized X-Git-Tag: glite-lb-server-bones_R_2_2_4_1~41 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=6ff12bf571cbd1ed21b07e15aaf66d2a5ee5c85c;p=jra1mw.git tar file exclude data read part optimized --- diff --git a/org.glite.jp.primary/src/sandbox_plugin.c b/org.glite.jp.primary/src/sandbox_plugin.c index bd5c5e1..7249d28 100644 --- a/org.glite.jp.primary/src/sandbox_plugin.c +++ b/org.glite.jp.primary/src/sandbox_plugin.c @@ -203,7 +203,7 @@ static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrv { if ( !strcmp(fileName, th_get_pathname(h->t)) ) { /* extract the file */ - int k, count = 0; + int k; size_t size; char buf[T_BLOCKSIZE]; char *value; @@ -215,24 +215,25 @@ static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrv value = (char *) malloc(size * sizeof(char) + 1); memset( value, 0, size * sizeof(char) + 1); - for (i = size; i > 0; i -= T_BLOCKSIZE) + for (i = 0; i < size; i += T_BLOCKSIZE) { k = tar_block_read(h->t, buf); - if (k != T_BLOCKSIZE) + if (k == -1) { - if (k != -1) err.code = EINVAL; - else err.code = errno; - + err.code = errno; err.desc = "tar_block_read"; return glite_jp_stack_error(ctx,&err); } - // XXX: returns always T_BLOCKSIZE, even if only 1B read - why?? - // call pread, which should return number of bytes read - if (i < T_BLOCKSIZE) { k=i; } + // tar_block_read calls glite_jppsbe_pread, which usually + // returns whole block (read from the middle of uploaded + // tar file + // so cut k in order to the last chunk had correct size + if (i + T_BLOCKSIZE > size) { + k = size - i; + } - strncpy(value + count, buf, k); - count += T_BLOCKSIZE; + strncpy(value + i, buf, k); } *attrval = malloc(2 * sizeof(**attrval) ); memset( (*attrval), 0, 2 * sizeof(**attrval));