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


Ignore:
Timestamp:
2011-04-01T11:34:41Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
66a54cc
Parents:
df3ad97 (diff), 27bdfa5 (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 from usb/development

File:
1 edited

Legend:

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

    rdf3ad97 r87b52c9  
    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
Note: See TracChangeset for help on using the changeset viewer.