SDB: modify sdb uninstall 00/12700/1
authorho.namkoong <ho.namkoong@samsung.com>
Thu, 21 Nov 2013 09:21:02 +0000 (18:21 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Thu, 21 Nov 2013 09:21:02 +0000 (18:21 +0900)
1. describe about pkg_id in help page
2. refine uninstall error message

Change-Id: I14f8d2ec7c42058f276163f0b72c2a5dcbd82ac2
Signed-off-by: ho.namkoong <ho.namkoong@samsung.com>
src/command_function.c
src/file_sync_functions.c
src/sdb_constants.c
src/strutils.c
src/strutils.h

index b95a3d143fe5d433e733992935dc8df7ac95b9e1..d588ecceb43834f145a329b9ee6801186c558e08 100644 (file)
@@ -645,20 +645,40 @@ static int get_pkgtype_from_app_id(const char* app_id, void** extargv) {
     }
     char buf[100] = "";
 
-    int rl_result = read_line(result, buf, 100);
-    if(rl_result < 0) {
-        D("Error to read buffer (fd=%d)\n", rl_result);
-        return rl_result;
+    int rl_result = read_lines(result, buf, 100);
+    if(rl_result <= 0) {
+        fprintf(stderr, "error: package '%s' does not exist\n", app_id);
+        return -1;
+    }
+
+    if(rl_result > 1) {
+        fprintf(stderr, "error: '%s' is not unique package id\n", app_id);
+        return -1;
     }
 
     sdb_close(result);
     result = -1;
 
+    char* end_line = strchr(buf, '\n');
+
+    if(end_line != NULL) {
+        *end_line = '\0';
+    }
+
     if(strstr(buf, "[tpk]") != NULL) {
         result = 1;
-    } else if(strstr(buf, "[wgt]") != NULL) {
+    }
+    else if(strstr(buf, "[wgt]") != NULL) {
         result = 0;
     }
+    else {
+        if(strstr(buf, "error") != NULL) {
+            fprintf(stderr, "%s\n", buf);
+        }
+        else {
+            fprintf(stderr, "error: not supported package type '%s'\n", buf);
+        }
+    }
     return result;
 }
 
index ad833b3b98bbb4a205d43782190210b29cf73305..385af7afe82ac9e8b83fc65d3fc1bfb4546966a8 100644 (file)
@@ -92,7 +92,6 @@ int initialize_remote(char* path, void** extargv) {
     int fd = sdb_connect("sync:", extargv);
 
     if(fd < 0) {
-        fprintf(stderr,"cannot sync remote: %s\n", strerror(errno));
         return -1;
     }
 
index 0f88bd740b5701232ac794c54920e6315a145c29..bc31029bdd6c3891234eebe8e031b6e378be57c2 100644 (file)
 
     const char* COMMANDLINE_UNINSTALL_NAME = "uninstall";
     const char* COMMANDLINE_UNINSTALL_DESC[] = {
-            "uninstall an app from the device"
+            "uninstall an app from the device",
+            "the <pkg_id> is an unique 10-digit unique identifier for the application. The following command shows an example:",
+            "Ex.) sdb uninstall ko983dw33q"
     };
     const int COMMANDLINE_UNINSTALL_DESC_SIZE = GET_ARRAY_SIZE(COMMANDLINE_UNINSTALL_DESC, char*);
-    const char* COMMANDLINE_UNINSTALL_ARG_DESC = "<app_id>";
+    const char* COMMANDLINE_UNINSTALL_ARG_DESC = "<pkg_id>";
     const int COMMANDLINE_UNINSTALL_MAX_ARG = 1;
     const int COMMANDLINE_UNINSTALL_MIN_ARG = 1;
 
index e7444b743c6d9cb2ca938291a244a9bfca38b6f6..d3d54175aca74afd060c29234b4d7e4d01082555 100755 (executable)
@@ -41,6 +41,23 @@ void free_strings(char **array, int n)
     }
 }
 
+int read_lines(const int fd, char* ptr, unsigned int maxlen)
+{
+    int lines = 0;
+    while (1) {
+        int len = read_line(fd, ptr, maxlen);
+        if(len < 0) {
+            break;
+        }
+        ptr += len;
+        *ptr++ = '\n';
+        len++;
+        maxlen -= len;
+        lines++;
+    }
+    return lines;
+}
+
 int read_line(const int fd, char* ptr, const unsigned int maxlen)
 {
     unsigned int n = 0;
index d5bf30b9e89f97f20461b1a7b3ae4cfcea69afde..ef8cd3b3befe6de9c53b71ec3c51356503f9b310 100644 (file)
@@ -5,6 +5,7 @@
 
 size_t tokenize(const char *str, const char *delim, char *tokens[], size_t max_tokens);
 void free_strings(char **array, int n);
+int read_lines(const int fd, char* ptr, const unsigned int maxlen);
 int read_line(const int fd, char* ptr, const unsigned int maxlen);
 char *s_strncpy(char *dest, const char *source, size_t n);
 size_t s_strnlen(const char *s, size_t maxlen);