Enlightenment CVS committal

Author  : chaos
Project : e17
Module  : apps/evfs

Dir     : e17/apps/evfs/src/bin


Modified Files:
        evfs_server_handle.c 


Log Message:
* File copy function now handles multiple files, as long as the dest file is a 
directory

===================================================================
RCS file: /cvs/e/e17/apps/evfs/src/bin/evfs_server_handle.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -3 -r1.63 -r1.64
--- evfs_server_handle.c        22 Jul 2006 06:09:26 -0000      1.63
+++ evfs_server_handle.c        6 Aug 2006 09:56:27 -0000       1.64
@@ -384,6 +384,8 @@
 {
    evfs_plugin *plugin;
    evfs_plugin *dst_plugin;
+   int num_files;
+   int c_file;
 
    char destination_file[PATH_MAX];
 
@@ -393,6 +395,15 @@
    int res;
    evfs_operation_files *op;
 
+   num_files = command->file_command.num_files;
+   printf("Num files at copy: %d\n", num_files);
+
+   /* < 2 files, no copy, dude */
+   if (num_files < 2) {
+          /*TODO error return here*/
+          return;
+   }
+
    /*Make a new evfs_operation, for client communication */
    if (root_command == command) {
           op = evfs_operation_files_new(client, root_command);
@@ -401,133 +412,153 @@
           op = EVFS_OPERATION_FILES(root_command->op);
    }
 
-   plugin =
-      evfs_get_plugin_for_uri(client->server,
-                              command->file_command.files[0]->plugin_uri);
-   dst_plugin =
-      evfs_get_plugin_for_uri(client->server,
-                              command->file_command.files[1]->plugin_uri);
-
-   if (plugin && dst_plugin)
-     {
-
-
-        /*Check for supported options */
-        if (!(EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_lstat &&
-              EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_open &&
-              EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_create &&
-             EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_read &&
-             EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_write))
-          {
-             printf("ARGH! Copy Not supported!\n");
-             evfs_operation_destroy(EVFS_OPERATION(op));
-             return;
-          }
-
-
-
-        /*Get the source file size */
-        (*EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_lstat) (command, 
&file_stat, 0);
-
-       /*Get destination file size*/
-        res =
-           (*EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_lstat) 
(command, &dest_stat, 1);
-
-
-
-        if (!S_ISDIR(file_stat.st_mode))
-          {
-                 evfs_operation_copy_task_add(EVFS_OPERATION(op), 
-                      evfs_filereference_clone(command->file_command.files[0]),
-                      evfs_filereference_clone(command->file_command.files[1]),
-                      file_stat, dest_stat, res);
-
-                 /*If we're a move, queue the delete of this dir..*/
-                 if (move) {
-                      evfs_operation_remove_task_add(EVFS_OPERATION(op), 
-                         
evfs_filereference_clone(command->file_command.files[0]),
-                         file_stat);
-                 }
-
-          } else {
-             Ecore_List *directory_list = NULL;
-
-                 evfs_operation_mkdir_task_add(EVFS_OPERATION(op), 
-                      
evfs_filereference_clone(command->file_command.files[1]));
-
-             /*First, we need a directory list... */
-             (*EVFS_PLUGIN_FILE(plugin)->functions->evfs_dir_list) (client, 
command,
-                                                  &directory_list);
-             if (directory_list)
-               {
-                  evfs_filereference *file = NULL;
-
-                  while ((file = ecore_list_remove_first(directory_list)))
-                    {
-                       evfs_filereference *source = NEW(evfs_filereference);
-                       evfs_filereference *dest = NEW(evfs_filereference);
-                       evfs_command *recursive_command = NEW(evfs_command);
-
-                       snprintf(destination_file, PATH_MAX, "%s%s",
-                                command->file_command.files[1]->path,
-                                strrchr(file->path, '/'));
-
-                       source->path = strdup(file->path);
-                       source->plugin_uri =
-                          strdup(command->file_command.files[0]->plugin_uri);
-                       source->parent = NULL;   /*TODO - handle nested uris */
-                       dest->path = strdup(destination_file);
-                       dest->plugin_uri =
-                          strdup(command->file_command.files[1]->plugin_uri);
-                       dest->parent = NULL;     /*TODO - handle nested uris */
-
-                       recursive_command->file_command.files =
-                          malloc(sizeof(evfs_filereference *) * 2);
-                       recursive_command->type = EVFS_CMD_FILE_COPY;
-                       recursive_command->file_command.files[0] = source;
-                       recursive_command->file_command.files[1] = dest;
-                       recursive_command->file_command.num_files = 2;
-
-                       //printf("Copy file '%s' to %s\n", file->path, 
destination_file);
-
-                       evfs_handle_file_copy(client, recursive_command,
+   for (c_file=0;c_file < num_files - 1; c_file++) {
+          plugin =
+             evfs_get_plugin_for_uri(client->server,
+                 command->file_command.files[c_file]->plugin_uri);
+       
+          dst_plugin =
+             evfs_get_plugin_for_uri(client->server,
+                     command->file_command.files[num_files-1]->plugin_uri);
+
+          if (plugin && dst_plugin) {
+
+               /*Check for supported options */
+               if (!(EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_lstat &&
+                     EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_open &&
+                     EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_create 
&&
+                     EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_read &&
+                     EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_write))
+                 {
+                    printf("ARGH! Copy Not supported!\n");
+                    evfs_operation_destroy(EVFS_OPERATION(op));
+                    return;
+                 }
+
+               /*Get the source file size */
+               (*EVFS_PLUGIN_FILE(plugin)->functions->evfs_file_lstat) 
(command, &file_stat, c_file);
+
+               /*Get destination file size*/
+               res =
+                  (*EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_lstat) 
(command, &dest_stat, num_files-1);
+
+               if (!S_ISDIR(file_stat.st_mode)) {
+                         evfs_filereference* rewrite_dest = NULL;
+
+                         rewrite_dest = 
+                            
evfs_filereference_clone(command->file_command.files[num_files-1]); 
+
+                         /*If dest_file exists, and is a dir - the dest file 
is rewritten
+                          * to be the original filename in the new dir*/
+                         if (res == EVFS_SUCCESS && 
S_ISDIR(dest_stat.st_mode)) {
+                               evfs_command* new_command;
+                               int final_len;
+                               char *slashpos = 
strrchr(command->file_command.files[c_file]->path, '/');
+                               printf("Filename is: %s\n", slashpos);
+                               
+                               
+                               final_len =strlen(rewrite_dest->path) + 
strlen(slashpos) +1 /* \0 */; 
+                               char *path_to = malloc(final_len);
+                               
+                               
+                               snprintf(path_to, final_len , "%s%s", 
command->file_command.files[num_files-1]->path, slashpos);
+                               printf("Multi file dest dir rewrite path: 
%s\n", path_to);
+
+                               free(rewrite_dest->path);
+                               rewrite_dest->path = path_to;
+
+                               new_command = 
evfs_file_command_single_build(rewrite_dest);
+                               res =
+                                 
(*EVFS_PLUGIN_FILE(dst_plugin)->functions->evfs_file_lstat)
+                                 (new_command, &dest_stat, 0);
+
+                               evfs_cleanup_file_command_only(new_command);
+                         }
+                       
+                         evfs_operation_copy_task_add(EVFS_OPERATION(op), 
+                              
evfs_filereference_clone(command->file_command.files[c_file]),
+                              rewrite_dest,
+                              file_stat, dest_stat, res);
+
+                         /*If we're a move, queue the delete of this dir..*/
+                         if (move) {
+                              
evfs_operation_remove_task_add(EVFS_OPERATION(op), 
+                                 
evfs_filereference_clone(command->file_command.files[c_file]),
+                                 file_stat);
+                         }
+
+                 } else {
+                    Ecore_List *directory_list = NULL;
+       
+                         evfs_operation_mkdir_task_add(EVFS_OPERATION(op), 
+                              
evfs_filereference_clone(command->file_command.files[num_files-1]));
+       
+                    /*First, we need a directory list... */
+                    (*EVFS_PLUGIN_FILE(plugin)->functions->evfs_dir_list) 
(client, command,
+                                                         &directory_list);
+                    if (directory_list) {
+                         evfs_filereference *file = NULL;
+
+                         while ((file = 
ecore_list_remove_first(directory_list))) {
+                              evfs_filereference *source = 
NEW(evfs_filereference);
+                              evfs_filereference *dest = 
NEW(evfs_filereference);
+                              evfs_command *recursive_command = 
NEW(evfs_command);
+       
+                              snprintf(destination_file, PATH_MAX, "%s%s",
+                                       
command->file_command.files[num_files-1]->path,
+                                       strrchr(file->path, '/'));
+
+                              source->path = strdup(file->path);
+                              source->plugin_uri =
+                                 
strdup(command->file_command.files[c_file]->plugin_uri);
+                              source->parent = NULL;   /*TODO - handle nested 
uris */
+                              dest->path = strdup(destination_file);
+                              dest->plugin_uri =
+                                 
strdup(command->file_command.files[num_files-1]->plugin_uri);
+                              dest->parent = NULL;     /*TODO - handle nested 
uris */
+
+                              recursive_command->file_command.files =
+                                 malloc(sizeof(evfs_filereference *) * 2);
+                              recursive_command->type = EVFS_CMD_FILE_COPY;
+                              recursive_command->file_command.files[c_file] = 
source;
+                              
recursive_command->file_command.files[num_files-1] = dest;
+                              recursive_command->file_command.num_files = 2;
+
+                              //printf("Copy file '%s' to %s\n", file->path, 
destination_file);
+       
+                              evfs_handle_file_copy(client, recursive_command,
                                              root_command, move);
 
-                       evfs_cleanup_filereference(file);
-                       evfs_cleanup_command(recursive_command,
+                              evfs_cleanup_filereference(file);
+                              evfs_cleanup_command(recursive_command,
                                             EVFS_CLEANUP_FREE_COMMAND);
-                    }
-                  ecore_list_destroy(directory_list);
+                         } //while
+                         ecore_list_destroy(directory_list);
 
-                 /*If we're a move, queue the delete of this dir (it should be 
empty - unless perms denied it....*/
-                 if (move) {
-                      evfs_operation_remove_task_add(EVFS_OPERATION(op), 
-                         
evfs_filereference_clone(command->file_command.files[0]),
-                         file_stat);
-                 }
-
-               }
-
-          }
-
-        /*Only send '100%' event when we're back at the top, or we aren't 
recursive */
-        if (command == root_command) {
-           /*evfs_file_progress_event_create(client, command, root_command, 
100,
-                                           EVFS_PROGRESS_TYPE_DONE);*/
+                         /*If we're a move, queue the delete of this dir (it 
should be empty - unless perms denied it....*/
+                         if (move) {
+                              
evfs_operation_remove_task_add(EVFS_OPERATION(op), 
+                                 
evfs_filereference_clone(command->file_command.files[c_file]),
+                                 file_stat);
+                         } //if
+                      }// root_if
+                 } //is_dir if
 
+     } else {
+        printf("Could not get plugins for both source and dest: (%s:%s)\n",
+               command->file_command.files[c_file]->plugin_uri,
+               command->file_command.files[num_files-1]->plugin_uri);
+     }
+  } //for loop if
+
+   /*Only send '100%' event when we're back at the top, or we aren't recursive 
*/
+   if (command == root_command) {
+          /*evfs_file_progress_event_create(client, command, root_command, 100,
+                                           EVFS_PROGRESS_TYPE_DONE);*/
           evfs_operation_tasks_print(EVFS_OPERATION(op));
           evfs_operation_queue_pending_add(EVFS_OPERATION(op));
+  }
 
-       }
-
-
-     }
-   else
-     {
-        printf("Could not get plugins for both source and dest: (%s:%s)\n",
-               command->file_command.files[0]->plugin_uri,
-               command->file_command.files[1]->plugin_uri);
-     }
 }
 
 void



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to