summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshingil.kang <shingil.kang@samsung.com>2014-04-01 15:55:59 +0900
committershingil.kang <shingil.kang@samsung.com>2014-04-03 10:11:09 +0900
commitc20bb912f4f715ecad4405cfdf4170984cf9c2ff (patch)
tree4c36a31c1ff8d242af71cca52303254eee5a1efe
parentb6a5984084230f32b28b9fc81ae8938362b4a00c (diff)
downloadsdb-c20bb912f4f715ecad4405cfdf4170984cf9c2ff.tar.gz
sdb-c20bb912f4f715ecad4405cfdf4170984cf9c2ff.tar.bz2
sdb-c20bb912f4f715ecad4405cfdf4170984cf9c2ff.zip
SDB: Fixed a bug where completing remote path automatically is not worked.
Change-Id: I35e4cf47bff26b009a630cf01295963dc1aeaefd Signed-off-by: shingil.kang <shingil.kang@samsung.com>
-rw-r--r--package/.sdb-completion.bash21
-rw-r--r--src/auto_complete.c25
2 files changed, 37 insertions, 9 deletions
diff --git a/package/.sdb-completion.bash b/package/.sdb-completion.bash
index d58fc0b..7623a06 100644
--- a/package/.sdb-completion.bash
+++ b/package/.sdb-completion.bash
@@ -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
diff --git a/src/auto_complete.c b/src/auto_complete.c
index f336503..b56d33b 100644
--- a/src/auto_complete.c
+++ b/src/auto_complete.c
@@ -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: