SDB: Fixed a bug where completing remote path automatically is not worked. 82/18782/3
authorshingil.kang <shingil.kang@samsung.com>
Tue, 1 Apr 2014 06:55:59 +0000 (15:55 +0900)
committershingil.kang <shingil.kang@samsung.com>
Thu, 3 Apr 2014 01:11:09 +0000 (10:11 +0900)
Change-Id: I35e4cf47bff26b009a630cf01295963dc1aeaefd
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
package/.sdb-completion.bash
src/auto_complete.c

index d58fc0b3e63bac535a3531291de64d3491dea64c..7623a06da1791e089475697179a56826783ed991 100644 (file)
@@ -1,10 +1,13 @@
 _sdb()
 {
-    #sdb path is defined in PATH environment variable
-    COMPREPLY=()
+    #check if the input is local or remote path.
+    INPUT_IS_PATH=0
 
+    #sdb path is defined in PATH environment variable
     SDB_PATH=$(eval eval echo \$\{COMP_WORDS\[0\]\})
 
+    COMPREPLY=()
+
     if [ ! -f ${SDB_PATH} ];
     then
         return 0;
@@ -14,6 +17,13 @@ _sdb()
     ARGS="autocomplete,${COMP_CWORD}"
 
     local IFS=$','
+
+    if [ -n ${COMP_WORDS[1]} ]; then
+        if [ "${COMP_WORDS[1]}" == "push" ] || [ "${COMP_WORDS[1]}" == "pull" ]; then
+           INPUT_IS_PATH=1
+       fi
+    fi
+
     for ((i=1; i < $((${COMP_CWORD} + 1)) ; i++))
     do
         #processing for echo options
@@ -30,9 +40,12 @@ _sdb()
     next=($("${SDB_PATH}" ${ARGS}))
     local IFS=$'\n'
     COMPREPLY=(${next})
-#    COMPREPLY=($(compgen -W "${next}" -- ${cur}))
+
+    if [ $INPUT_IS_PATH == 0 ]; then 
+        COMPREPLY=( "${COMPREPLY[@]/%/ }" )   #add trailing space to each
+    fi
 
     return 0
 }
 
-complete -o filenames -F _sdb sdb
+complete -o nospace -F _sdb sdb
index f3365035ae55c7b2fd527431c2a777a3c83f6929..b56d33b49e4006542d5d0599f82d4b1c7c18d3f9 100644 (file)
@@ -34,6 +34,7 @@
 #include "strutils.h"
 #include "auto_complete.h"
 #include "file_sync_service.h"
+#include "log.h"
 
 static int parse_opt(int argc, char** argv);
 static int parse_cmd(int argc, char** argv);
@@ -60,6 +61,7 @@ static int COMPLETE_FLAG = 0;
 static FILE* AC_STDOUT = NULL;
 static FILE* AC_STDERR = NULL;
 static const char IFS = '\n';
+static const char PATH_SEPARATOR = '\/';
 
 static struct ac_element emulator_short = {
         .keyword = "-e",
@@ -501,6 +503,7 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) {
         goto finalize;
     }
     struct dirent* de;
+    struct stat statbuf;
 
     while((de = readdir(d))) {
         char* file_name = de->d_name;
@@ -517,6 +520,13 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) {
         char src_full_path[PATH_MAX];
         append_file(src_full_path, src_dir, file_name, PATH_MAX);
 
+        // get file stat
+        if(stat(src_full_path, &statbuf) == -1)
+        {
+            fprintf(stderr, "error: exception occurred while getting file stat: %s\n", src_full_path);
+            goto finalize;
+        }
+
         char* src_ptr = src_full_path;
         if(pwd_flag) {
             src_ptr += 2;
@@ -526,9 +536,12 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) {
             fprintf(AC_STDOUT, "%s%c", src_ptr, IFS);
         }
         else {
-            int len = strnlen(not_complete_char[0], 255);
+            int len = strnlen(not_complete_char[0], PATH_MAX);
             if(!strncmp(not_complete_char[0], src_ptr, len)) {
-                fprintf(AC_STDOUT, "%s%c", src_ptr, IFS);
+                if(S_ISDIR(statbuf.st_mode))
+                    fprintf(AC_STDOUT, "%s%c%c", src_ptr, PATH_SEPARATOR, IFS);
+                else
+                    fprintf(AC_STDOUT, "%s%c", src_ptr, IFS);
             }
         }
     }
@@ -612,12 +625,14 @@ static void print_remote_dirlist(char* src_dir, char** not_complete_char) {
             fprintf(AC_STDOUT, "%s%c", src_full_path, IFS);
         }
         else {
-            int len = strnlen(not_complete_char[0], 255);
+            int len = strnlen(not_complete_char[0], PATH_MAX);
             if(!strncmp(not_complete_char[0], src_full_path, len)) {
-                fprintf(AC_STDOUT, "%s%c", src_full_path, IFS);
+                if(S_ISDIR(msg.dent.mode))
+                   fprintf(AC_STDOUT, "%s%c%c", src_full_path, PATH_SEPARATOR, IFS);
+                else
+                   fprintf(AC_STDOUT, "%s%c", src_full_path, IFS);
             }
         }
-
     }
 
 finalize: