Enlightenment CVS committal Author : lordchaos Project : e17 Module : apps/evfs
Dir : e17/apps/evfs/src/plugins Modified Files: evfs_fs_bzip2.c evfs_fs_tar.c Log Message: * Handle tar file paths correctly! * Close a bzip2 file/free memory when we close parent =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/plugins/evfs_fs_bzip2.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- evfs_fs_bzip2.c 2 Nov 2005 11:13:50 -0000 1.3 +++ evfs_fs_bzip2.c 3 Nov 2005 12:39:46 -0000 1.4 @@ -59,6 +59,7 @@ #define BZIP2_BUFFER 5000 +Ecore_Hash* bzip_hash; typedef struct bzip2_file { evfs_filereference* ref; bz_stream stream; @@ -67,7 +68,7 @@ } bzip2_file; -bzip2_file* bfile; + evfs_plugin_functions* evfs_plugin_init() { @@ -77,6 +78,7 @@ functions->evfs_client_disconnect = &evfs_client_disconnect; functions->evfs_file_open = &evfs_file_open; functions->evfs_file_read = &evfs_file_read; + functions->evfs_file_close = &evfs_file_close; /*functions->evfs_dir_list = &evfs_dir_list; @@ -85,7 +87,7 @@ functions->evfs_monitor_stop = &evfs_monitor_stop; functions->evfs_file_stat = &evfs_file_stat; - functions->evfs_file_close = &evfs_file_close; + functions->evfs_file_seek = &evfs_file_seek; @@ -94,16 +96,11 @@ functions->evfs_file_create = &evfs_file_create;*/ - bfile = NEW(bzip2_file); - bfile->buffer = malloc(sizeof(char)*BZIP2_BUFFER); - bfile->stream.next_in = (char*)bfile->buffer; - bfile->stream.avail_in = 0; - - if (BZ2_bzDecompressInit(&bfile->stream,0,0) != BZ_OK) { - printf("Error in bzip2 init\n"); - } - + /*FIXME - This is bad - by using a direct compare, we preclude clients using + * an 'identical' evfs_filereference with a different pointer*/ + /*TODO - Fix this by creating evfs_filereference_compare for Ecore_Hash*/ + bzip_hash = ecore_hash_new(ecore_direct_hash, ecore_direct_compare); return functions; @@ -122,18 +119,31 @@ int evfs_file_open(evfs_client* client, evfs_filereference* file) { evfs_filereference* f_par = file->parent; + bzip2_file* bfile; /*Handle decomp init*/ + printf("Opening bzip file '%s'\n", file->path); + + bfile = NEW(bzip2_file); + bfile->buffer = malloc(sizeof(char)*BZIP2_BUFFER); + bfile->stream.next_in = (char*)bfile->buffer; + bfile->stream.avail_in = 0; + + if (BZ2_bzDecompressInit(&bfile->stream,0,0) != BZ_OK) { + printf("Error in bzip2 init\n"); + } + ecore_hash_set(bzip_hash, file, bfile); /*Open the file in the parent*/ return evfs_uri_open(client, f_par); } - +/*FUTURE DOC NOTE - Takes the child file, not the parent */ int evfs_bzip2_populate_buffer(evfs_client* client, evfs_filereference* ref) { int res; + bzip2_file* bfile = ecore_hash_get(bzip_hash, ref); if (bfile->stream.avail_in > 0) { //printf("No need to read, got data already..\n"); @@ -141,7 +151,7 @@ } - res = evfs_uri_read(client,ref, bfile->buffer, BZIP2_BUFFER); + res = evfs_uri_read(client,ref->parent, bfile->buffer, BZIP2_BUFFER); //printf("Read %d bytes at bzip2_read from fd %d using filename %s\n", res, ref->fd, ref->path); if (res > 0) { @@ -158,6 +168,7 @@ int evfs_file_read(evfs_client* client, evfs_filereference* file, char* bytes, long size) { evfs_filereference* f_par = file->parent; + bzip2_file* bfile = ecore_hash_get(bzip_hash, file); int bz_result; int r_size; @@ -168,7 +179,7 @@ bfile->stream.avail_out = size; while (bfile->stream.avail_out != 0) { - int res = evfs_bzip2_populate_buffer(client,f_par); + int res = evfs_bzip2_populate_buffer(client,file); //printf("Avail_out starts at %d\n", bfile->stream.avail_out); bz_result = BZ2_bzDecompress(&bfile->stream); //printf("Avail_out goes to %d\n", bfile->stream.avail_out); @@ -186,9 +197,19 @@ } else if (bfile->stream.avail_out == size) { return 0; /*EOF*/ } +} +int evfs_file_close(evfs_filereference* file) { + bzip2_file* bfile = ecore_hash_get(bzip_hash, file); - + if (BZ2_bzDecompressEnd(&bfile->stream) != BZ_OK) { + printf("Error in bzip2 end\n"); + } + + free(bfile->buffer); + ecore_hash_remove(bzip_hash, file); + free(bfile); + } =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/plugins/evfs_fs_tar.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- evfs_fs_tar.c 31 Oct 2005 03:32:55 -0000 1.6 +++ evfs_fs_tar.c 3 Nov 2005 12:39:46 -0000 1.7 @@ -39,6 +39,16 @@ #include <tarpet.h> +evfs_filereference* evfs_file_top_level_find(evfs_filereference* file) { + evfs_filereference* top = file; + + while (top->parent) { + top = top->parent; + } + + return top; +} + /*Main file wrappers*/ int evfs_file_remove(char* src); @@ -225,6 +235,8 @@ Ecore_List* keys; char* dir, *key; int count; + int find = 0; + evfs_filereference* top_ref; printf("At tar dir_list handler\n"); @@ -242,15 +254,19 @@ printf("Magic is '%s'\n", block.p.magic); printf("Flag is %d\n", block.p.typeflag);*/ - tar_name_split(&block, tar); + find++; } else { //printf("No magic - '%s'\n", block.p.magic); } } - + evfs_uri_close(client, p_ref); - ecore_hash_set(tar_cache, strdup(p_ref->path), tar); + if (!find) { printf("*** No GNU-TAR blocks found in file\n"); } + else { printf("Found %d tar blocks total\n"); } + + printf("Recording tar file as '%s'\n", evfs_file_top_level_find(p_ref)->path); + ecore_hash_set(tar_cache, strdup(evfs_file_top_level_find(p_ref)->path), tar); return tar; @@ -269,7 +285,7 @@ printf("Listing tar file dir: '%s'\n", com->file_command.files[0]->path); - if (!(file = ecore_hash_get(tar_cache, com->file_command.files[0]->parent->path))) { + if (!(file = ecore_hash_get(tar_cache, evfs_file_top_level_find(com->file_command.files[0])->path))) { file = evfs_tar_load_tar(client, com->file_command.files[0]); } ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs