Changeset 3951


Ignore:
Timestamp:
Mar 18, 2019, 1:22:01 PM (6 years ago)
Author:
bird
Message:

unlink() shall not delete directories, but return EISDIR.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsUnlink.c

    r2542 r3951  
    4545
    4646/**
    47  * Unlinks a file, directory, symlink, dev, pipe or socket.
     47 * Unlinks a file, symlink, dev, pipe or socket, but not a directory.
    4848 *
    4949 * @returns 0 on success.
     
    6565     */
    6666    char szNativePath[PATH_MAX];
    67     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePath[0], NULL);
     67    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK, &szNativePath[0], NULL);
    6868    if (rc)
    6969        LIBCLOG_ERROR_RETURN_INT(rc);
     
    105105         *      3) we are denied access - network, hpfs386 or SES.
    106106         *
    107          * If it's either of the first two we are subject to race conditions, so we
    108          * have to retry. The third cause is distiguishable from the two othes by
    109          * the failing DosSetPathInfo.
     107         * If it's the first we are subject to race conditions, so we have to retry.
     108         * The third cause is distiguishable from the two othes by the failing DosSetPathInfo.
    110109         */
    111         int fDirectory = 0;
    112110        for (unsigned i = 0; (rc == ERROR_ACCESS_DENIED || rc == ERROR_PATH_NOT_FOUND) && i < 2; i++)
    113111        {
     
    116114            if (!rc)
    117115            {
    118                 fDirectory = (fsts3.attrFile & FILE_DIRECTORY) != 0;
     116                /* Directory? */
     117                if ((fsts3.attrFile & FILE_DIRECTORY) != 0)
     118                {
     119                    rc = ERROR_DIRECTORY;
     120                    break;
     121                }
    119122
    120123                /* turn of the read-only attribute */
     
    133136
    134137                /* retry */
    135                 if (fDirectory)
    136                     rc = DosDeleteDir((PCSZ)&szNativePath[0]);
    137                 else if (s_fUseForce == 1)
     138                if (s_fUseForce == 1)
    138139                    rc = DosForceDelete((PCSZ)&szNativePath[0]);
    139140                else
     
    155156        {
    156157            if (rc == ERROR_ACCESS_DENIED)
    157                 rc = fDirectory ? -ENOTEMPTY : -EACCES;
     158                rc = -EACCES;
     159            else if (rc == ERROR_DIRECTORY)
     160                rc = -EISDIR;
    158161            else
    159162                rc = -__libc_native2errno(rc);
  • trunk/libc/src/kNIX/os2/b_fsUnlink.c

    r3862 r3951  
    3030
    3131/**
    32  * Unlinks a file, directory, symlink, dev, pipe or socket.
     32 * Unlinks a file, symlink, dev, pipe or socket, but not a directory.
    3333 *
    3434 * @returns 0 on success.
     
    5050     */
    5151    char szNativePath[PATH_MAX];
    52     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePath[0], NULL);
     52    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK, &szNativePath[0], NULL);
    5353    if (rc)
    5454        LIBCLOG_ERROR_RETURN_INT(rc);
     
    9090         *      3) we are denied access - network, hpfs386 or SES.
    9191         *
    92          * If it's either of the first two we are subject to race conditions, so we
    93          * have to retry. The third cause is distiguishable from the two othes by
    94          * the failing DosSetPathInfo.
     92         * If it's the first we are subject to race conditions, so we have to retry.
     93         * The third cause is distiguishable from the two othes by the failing DosSetPathInfo.
    9594         */
    96         int fDirectory = 0;
    9795        for (unsigned i = 0; (rc == ERROR_ACCESS_DENIED || rc == ERROR_PATH_NOT_FOUND) && i < 2; i++)
    9896        {
     
    10199            if (!rc)
    102100            {
    103                 fDirectory = (fsts3.attrFile & FILE_DIRECTORY) != 0;
     101                /* Directory? */
     102                if ((fsts3.attrFile & FILE_DIRECTORY) != 0)
     103                {
     104                    rc = ERROR_DIRECTORY;
     105                    break;
     106                }
    104107
    105108                /* turn of the read-only attribute */
     
    118121
    119122                /* retry */
    120                 if (fDirectory)
    121                     rc = DosDeleteDir((PCSZ)&szNativePath[0]);
    122                 else if (s_fUseForce == 1)
     123                if (s_fUseForce == 1)
    123124                    rc = DosForceDelete((PCSZ)&szNativePath[0]);
    124125                else
     
    140141        {
    141142            if (rc == ERROR_ACCESS_DENIED)
    142                 rc = fDirectory ? -ENOTEMPTY : -EACCES;
     143                rc = -EACCES;
     144            else if (rc == ERROR_DIRECTORY)
     145                rc = -EISDIR;
    143146            else
    144147                rc = -__libc_back_native2errno(rc);
Note: See TracChangeset for help on using the changeset viewer.