[PATCH] shell32: Don't use Carbon on Mac OS to find the Trash.

Ken Thomases ken at codeweavers.com
Thu Jul 19 15:34:02 CDT 2018


On Jul 19, 2018, at 3:16 PM, Chip Davis <cdavis at codeweavers.com> wrote:
> 
> BOOL TRASH_CanTrashFile(LPCWSTR wszPath)
> {
> -    char *unix_path;
> -    OSStatus status;
> -    FSRef ref;
> -    FSCatalogInfo catalogInfo;
> +    char *unix_path, *trash_path;
> +    const char *base_name;
> +    BOOL can_trash;
> +    struct stat st;
> 
>     TRACE("(%s)\n", debugstr_w(wszPath));
> +
>     if (!(unix_path = wine_get_unix_file_name(wszPath)))
>         return FALSE;
> -
> -    status = FSPathMakeRef((UInt8*)unix_path, &ref, NULL);
> +    if (!(trash_path = TRASH_GetTrashPath(unix_path, &base_name)))
> +    {
> +        heap_free(unix_path);
> +        return FALSE;
> +    }
> +    can_trash = stat(trash_path, &st) == 0;
>     heap_free(unix_path);
> -    if (status == noErr)
> -        status = FSGetCatalogInfo(&ref, kFSCatInfoVolume, &catalogInfo, NULL,
> -                                  NULL, NULL);
> -    if (status == noErr)
> -        status = FSFindFolder(catalogInfo.volume, kTrashFolderType,
> -                              kCreateFolder, &ref);

The old code would attempt to create the Trash folder if it doesn't exist, but your new code doesn't.

> -
> -    return (status == noErr);
> +    heap_free(trash_path);
> +    return can_trash;
> }
> 
> BOOL TRASH_TrashFile(LPCWSTR wszPath)
> {
> -    char *unix_path;
> -    OSStatus status;
> +    char *unix_path, *trash_path;
> +    const char *base_name;
> +    int res;
> 
>     TRACE("(%s)\n", debugstr_w(wszPath));
>     if (!(unix_path = wine_get_unix_file_name(wszPath)))
>         return FALSE;
> +    if (!(trash_path = TRASH_GetTrashPath(unix_path, &base_name)))
> +    {
> +        heap_free(unix_path);
> +        return FALSE;
> +    }
> 
> -    status = FSPathMoveObjectToTrashSync(unix_path, NULL, kFSFileOperationSkipPreflight);
> +    lstrcatA(trash_path, "/");
> +    lstrcatA(trash_path, base_name);

trash_path is just big enough for the path to the Trash directory.  You can't concatenate to it without reallocating it larger.

> +
> +    res = rename(unix_path, trash_path);
> 
>     heap_free(unix_path);
> -    return (status == noErr);
> +    heap_free(trash_path);
> +    return (res != -1);
> }

-Ken




More information about the wine-devel mailing list