Changeset d011038 in mainline for uspace/app/bdsh/cmds/modules/rm/rm.c


Ignore:
Timestamp:
2011-03-29T20:12:44Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8f17503
Parents:
c4fb95d3 (diff), 93ebe4e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rc4fb95d3 rd011038  
    101101}
    102102
     103static unsigned int rm_recursive_not_empty_dirs(const char *path)
     104{
     105        DIR *dirp;
     106        struct dirent *dp;
     107        char buff[PATH_MAX];
     108        unsigned int scope;
     109        unsigned int ret = 0;
     110
     111        dirp = opendir(path);
     112        if (!dirp) {
     113                /* May have been deleted between scoping it and opening it */
     114                cli_error(CL_EFAIL, "Could not open %s", path);
     115                return ret;
     116        }
     117
     118        memset(buff, 0, sizeof(buff));
     119        while ((dp = readdir(dirp))) {
     120                snprintf(buff, PATH_MAX - 1, "%s/%s", path, dp->d_name);
     121                scope = rm_scope(buff);
     122                switch (scope) {
     123                case RM_BOGUS:
     124                        break;
     125                case RM_FILE:
     126                        ret += rm_single(buff);
     127                        break;
     128                case RM_DIR:
     129                        ret += rm_recursive(buff);
     130                        break;
     131                }
     132        }
     133       
     134        return ret;
     135}
     136
    103137static unsigned int rm_recursive(const char *path)
    104138{
    105139        int rc;
     140        unsigned int ret = 0;
    106141
    107142        /* First see if it will just go away */
     
    111146
    112147        /* Its not empty, recursively scan it */
    113         cli_error(CL_ENOTSUP,
    114                 "Can not remove %s, directory not empty", path);
    115         return 1;
     148        ret = rm_recursive_not_empty_dirs(path);
     149
     150        /* Delete directory */
     151        rc = rmdir(path);
     152        if (rc == 0)
     153                return ret;
     154
     155        cli_error(CL_ENOTSUP, "Can not remove %s", path);
     156
     157        return ret + 1;
    116158}
    117159
     
    227269                }
    228270                memset(buff, 0, sizeof(buff));
    229                 snprintf(buff, len, argv[i]);
     271                snprintf(buff, len, "%s", argv[i]);
    230272
    231273                scope = rm_scope(buff);
Note: See TracChangeset for help on using the changeset viewer.