Changeset 1c481ee in mainline


Ignore:
Timestamp:
2019-03-09T15:40:05Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
587867a
Parents:
c56a3eb
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-03-02 15:55:07)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-03-09 15:40:05)
Message:

This commit fixes #684 and adds autocompletion for subdirectories in search_path. The original implementation of find_command()
will find cmd inside the working directory even without
the prefix './'. However, those cmds would have not been visible in
the auto completion. This commit prevents this from happening.

The problem can be traced back to vfs_absolutize() which treats paths
without the './' prefix as relative paths. The changes made unsures
that only relative or absolute pathes will be passed to vfs_absolutize()

This commit also fixes the problem, that subdirectories inside the
search_path would not be autocomplete. BDSH would execute such paths.
The reason being is that such paths was interpreted as relative paths.
Now BDSH makes a distinction between relatives paths or paths inside
search_path

Location:
uspace/app/bdsh
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/compl.c

    rc56a3eb r1c481ee  
    4040#include "exec.h"
    4141#include "tok.h"
     42#include "util.h"
    4243
    4344static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state);
     
    209210                }
    210211                *cstart += rpath_sep + 1 - prefix;
    211                 free(prefix);
    212                 prefix = NULL;
    213212
    214213                cs->path_list = malloc(sizeof(char *) * 2);
     
    217216                        goto error;
    218217                }
    219                 cs->path_list[0] = dirname;
     218
     219                if (!is_path(prefix) && cs->is_command) {
     220                        cs->path_list[0] = malloc(sizeof(char) * PATH_MAX);
     221                        int ret = snprintf(cs->path_list[0], PATH_MAX, "%s/%s", search_dir[0], dirname);
     222                        if (ret < 0 || ret >= PATH_MAX) {
     223                                retval = ENOMEM;
     224                                goto error;
     225                        }
     226                } else {
     227                        cs->path_list[0] = dirname;
     228                }
     229
    220230                cs->path_list[1] = NULL;
    221231                /*
  • uspace/app/bdsh/exec.c

    rc56a3eb r1c481ee  
    7272{
    7373        /* The user has specified a full or relative path, just give it back. */
    74         if (-1 != try_access(cmd)) {
    75                 return str_dup(cmd);
     74        if (is_path(cmd)) {
     75                if (-1 != try_access(cmd)) {
     76                        return str_dup(cmd);
     77                }
    7678        }
    7779
  • uspace/app/bdsh/util.c

    rc56a3eb r1c481ee  
    7474        return 0;
    7575}
     76
     77/*
     78 * Returns true if the string is a relative or an absolute path
     79 */
     80bool is_path(const char *cmd)
     81{
     82
     83        bool ret = str_lcmp(cmd, "/", 1) == 0;
     84        ret = ret || str_lcmp(cmd, "./", 2) == 0;
     85        ret = ret || str_lcmp(cmd, "../", 3) == 0;
     86
     87        return ret;
     88}
  • uspace/app/bdsh/util.h

    rc56a3eb r1c481ee  
    3131
    3232#include "scli.h"
     33#include <stdbool.h>
    3334
    3435/* Utility functions */
    3536extern unsigned int cli_count_args(char **);
    3637extern unsigned int cli_set_prompt(cliuser_t *usr);
     38extern bool is_path(const char *cmd);
    3739
    3840#endif
Note: See TracChangeset for help on using the changeset viewer.