2 * The freedesktop.org Trash, implemented using the 0.7 spec version
3 * (see http://www.ramendik.ru/docs/trashspec.html)
5 * Copyright (C) 2006 Mikolaj Zalewski
6 * Copyright 2011 Jay Yang
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
31 #include <sys/types.h>
32 #ifdef HAVE_SYS_STAT_H
33 # include <sys/stat.h>
35 #ifdef HAVE_SYS_MOUNT_H
36 # include <sys/mount.h>
55 #include "wine/debug.h"
56 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(trash
);
62 * The item ID of a trashed element is built as follows:
63 * NUL byte - in most PIDLs the first byte is the type so we keep it constant
64 * WIN32_FIND_DATAW structure - with data about original file attributes
65 * bucket name - currently only an empty string meaning the home bucket is supported
66 * trash file name - a NUL-terminated string
68 static HRESULT
TRASH_CreateSimplePIDL(LPCSTR filename
, const WIN32_FIND_DATAW
*data
, LPITEMIDLIST
*pidlOut
)
70 LPITEMIDLIST pidl
= SHAlloc(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1+2);
74 pidl
->mkid
.cb
= (USHORT
)(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1);
75 pidl
->mkid
.abID
[0] = 0;
76 memcpy(pidl
->mkid
.abID
+1, data
, sizeof(WIN32_FIND_DATAW
));
77 pidl
->mkid
.abID
[1+sizeof(WIN32_FIND_DATAW
)] = 0;
78 lstrcpyA((LPSTR
)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1), filename
);
79 *(USHORT
*)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1) = 0;
84 /***********************************************************************
85 * TRASH_UnpackItemID [Internal]
88 * Extract the information stored in an Item ID. The WIN32_FIND_DATA contains
89 * the information about the original file. The data->ftLastAccessTime contains
93 * [I] id : the ID of the item
94 * [O] data : the WIN32_FIND_DATA of the original file. Can be NULL is not needed
96 HRESULT
TRASH_UnpackItemID(LPCSHITEMID id
, WIN32_FIND_DATAW
*data
)
98 if (id
->cb
< 2+1+sizeof(WIN32_FIND_DATAW
)+2)
100 if (id
->abID
[0] != 0 || id
->abID
[1+sizeof(WIN32_FIND_DATAW
)] != 0)
102 if (memchr(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+1, 0, id
->cb
-(2+1+sizeof(WIN32_FIND_DATAW
)+1)) == NULL
)
106 *data
= *(const WIN32_FIND_DATAW
*)(id
->abID
+1);
112 static char *TRASH_GetTrashPath(const char *unix_path
, const char **base_name
)
114 struct statfs stfs
, home_stfs
;
115 struct passwd
*user
= getpwuid(geteuid());
119 if (statfs(unix_path
, &stfs
) == -1)
121 if (statfs(user
->pw_dir
, &home_stfs
) == -1)
124 *base_name
= strrchr(unix_path
, '/');
126 *base_name
= unix_path
;
129 name_size
= lstrlenA(*base_name
);
131 /* If the file exists on the same volume as the user's home directory,
132 * we can use the User domain Trash folder. Otherwise, we have to use
133 * <volume>/.Trashes/<uid>.
135 if (memcmp(&stfs
.f_fsid
, &home_stfs
.f_fsid
, sizeof(fsid_t
)) == 0)
137 size_t home_size
= lstrlenA(user
->pw_dir
);
138 trash_path
= heap_alloc(home_size
+ sizeof("/.Trash/") + name_size
);
141 memcpy(trash_path
, user
->pw_dir
, home_size
);
142 memcpy(trash_path
+home_size
, "/.Trash", sizeof("/.Trash"));
146 size_t vol_size
= lstrlenA(stfs
.f_mntonname
);
147 /* 10 for the maximum length of a 32-bit integer + 1 for the \0 */
148 size_t trash_size
= vol_size
+ sizeof("/.Trashes/") + 10 + 1 + name_size
+ 1;
149 trash_path
= heap_alloc(trash_size
);
152 snprintf(trash_path
, trash_size
, "%s/.Trashes/%u", stfs
.f_mntonname
, geteuid());
157 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
159 char *unix_path
, *trash_path
;
160 const char *base_name
;
164 TRACE("(%s)\n", debugstr_w(wszPath
));
166 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
168 if (!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
170 heap_free(unix_path
);
173 can_trash
= stat(trash_path
, &st
) == 0;
174 if (!can_trash
&& errno
== ENOENT
)
176 /* Recursively create the Trash folder. */
177 char *p
= trash_path
;
179 while ((p
= strchr(p
, '/')) != NULL
)
182 if (mkdir(trash_path
, 0755) == -1 && errno
!= EEXIST
)
184 heap_free(unix_path
);
185 heap_free(trash_path
);
192 heap_free(unix_path
);
193 heap_free(trash_path
);
197 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
199 char *unix_path
, *trash_path
;
200 const char *base_name
;
203 TRACE("(%s)\n", debugstr_w(wszPath
));
204 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
206 if (!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
208 heap_free(unix_path
);
212 lstrcatA(trash_path
, "/");
213 lstrcatA(trash_path
, base_name
);
215 res
= rename(unix_path
, trash_path
);
217 heap_free(unix_path
);
218 heap_free(trash_path
);
223 * - set file deletion time
224 * - set original file location
226 HRESULT
TRASH_GetDetails(const char *trash_path
, const char *name
, WIN32_FIND_DATAW
*data
)
230 int trash_path_length
= lstrlenA(trash_path
);
231 int name_length
= lstrlenA(name
);
232 char *path
= SHAlloc(trash_path_length
+1+name_length
+1);
236 if(!once
++) FIXME("semi-stub\n");
238 if(!path
) return E_OUTOFMEMORY
;
239 memcpy(path
, trash_path
, trash_path_length
);
240 path
[trash_path_length
] = '/';
241 memcpy(path
+trash_path_length
+1, name
, name_length
+1);
243 ret
= lstat(path
, &stats
);
245 if(ret
== -1) return S_FALSE
;
246 memset(data
, 0, sizeof(*data
));
247 data
->nFileSizeHigh
= stats
.st_size
>>32;
248 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
249 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
251 if(!MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, data
->cFileName
, MAX_PATH
))
256 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
258 WCHAR volume_path
[MAX_PATH
];
259 char *unix_path
, *trash_path
;
260 const char *base_name
;
261 struct dirent
*entry
;
267 TRACE("(%s %p %p)\n", debugstr_w(path
), pidls
, count
);
270 FIXME("All trashes enumeration not supported\n");
271 volume_path
[0] = 'C';
272 volume_path
[1] = ':';
275 if(!GetVolumePathNameW(path
, volume_path
, MAX_PATH
))
279 if(!(unix_path
= wine_get_unix_file_name(volume_path
)))
280 return E_OUTOFMEMORY
;
282 if(!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
283 return E_OUTOFMEMORY
;
285 if(!(dir
= opendir(trash_path
))) return E_FAIL
;
286 ret
= heap_alloc(ret_size
* sizeof(*ret
));
289 return E_OUTOFMEMORY
;
291 while((entry
= readdir(dir
))) {
292 WIN32_FIND_DATAW data
;
294 if(!lstrcmpA(entry
->d_name
, ".") || !lstrcmpA(entry
->d_name
, ".." )
295 || !lstrcmpA(entry
->d_name
, ".DS_Store"))
299 LPITEMIDLIST
*resized
;
301 resized
= heap_realloc(ret
, ret_size
* sizeof(*ret
));
302 if(!resized
) hr
= E_OUTOFMEMORY
;
307 hr
= TRASH_GetDetails(trash_path
, entry
->d_name
, &data
);
308 if(hr
== S_FALSE
) continue;
311 hr
= TRASH_CreateSimplePIDL(entry
->d_name
, &data
, ret
+i
);
313 while(i
>0) SHFree(ret
+(--i
));
322 *pidls
= SHAlloc(sizeof(**pidls
) * i
);
324 while(i
>0) SHFree(ret
+(--i
));
326 return E_OUTOFMEMORY
;
329 for(i
--; i
>=0; i
--) (*pidls
)[i
] = ret
[i
];
334 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
)
340 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
346 #else /* __APPLE__ */
348 static CRITICAL_SECTION TRASH_Creating
;
349 static CRITICAL_SECTION_DEBUG TRASH_Creating_Debug
=
351 0, 0, &TRASH_Creating
,
352 { &TRASH_Creating_Debug
.ProcessLocksList
,
353 &TRASH_Creating_Debug
.ProcessLocksList
},
354 0, 0, { (DWORD_PTR
)__FILE__
": TRASH_Creating"}
356 static CRITICAL_SECTION TRASH_Creating
= { &TRASH_Creating_Debug
, -1, 0, 0, 0, 0 };
358 static const char trashinfo_suffix
[] = ".trashinfo";
359 static const char trashinfo_header
[] = "[Trash Info]\n";
360 static const char trashinfo_group
[] = "Trash Info";
369 static TRASH_BUCKET
*home_trash
=NULL
;
371 static char *init_home_dir(const char *subpath
)
373 char *path
= XDG_BuildPath(XDG_DATA_HOME
, subpath
);
374 if (path
== NULL
) return NULL
;
375 if (!XDG_MakeDirs(path
))
377 ERR("Couldn't create directory %s (errno=%d). Trash won't be available\n", debugstr_a(path
), errno
);
384 static TRASH_BUCKET
*TRASH_CreateHomeBucket(void)
386 TRASH_BUCKET
*bucket
;
387 struct stat trash_stat
;
388 char *trash_path
= NULL
;
390 bucket
= SHAlloc(sizeof(TRASH_BUCKET
));
396 memset(bucket
, 0, sizeof(*bucket
));
397 bucket
->info_dir
= init_home_dir("Trash/info/");
398 if (bucket
->info_dir
== NULL
) goto error
;
399 bucket
->files_dir
= init_home_dir("Trash/files/");
400 if (bucket
->files_dir
== NULL
) goto error
;
402 trash_path
= XDG_BuildPath(XDG_DATA_HOME
, "Trash/");
403 if (stat(trash_path
, &trash_stat
) == -1)
405 bucket
->device
= trash_stat
.st_dev
;
412 SHFree(bucket
->info_dir
);
413 SHFree(bucket
->files_dir
);
419 static BOOL
TRASH_EnsureInitialized(void)
421 if (home_trash
== NULL
)
423 EnterCriticalSection(&TRASH_Creating
);
424 if (home_trash
== NULL
)
425 home_trash
= TRASH_CreateHomeBucket();
426 LeaveCriticalSection(&TRASH_Creating
);
429 if (home_trash
== NULL
)
431 ERR("Couldn't initialize home trash (errno=%d)\n", errno
);
437 static BOOL
file_good_for_bucket(const TRASH_BUCKET
*pBucket
, const struct stat
*file_stat
)
439 if (pBucket
->device
!= file_stat
->st_dev
)
444 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
446 struct stat file_stat
;
450 TRACE("(%s)\n", debugstr_w(wszPath
));
451 if (!TRASH_EnsureInitialized()) return FALSE
;
452 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
454 ret
= lstat(unix_path
, &file_stat
);
455 heap_free(unix_path
);
458 return file_good_for_bucket(home_trash
, &file_stat
);
462 * Try to create a single .trashinfo file. Return TRUE if successful, else FALSE
464 static BOOL
try_create_trashinfo_file(const char *info_dir
, const char *file_name
,
465 const char *original_file_name
)
467 SYSTEMTIME curr_time
;
469 char *path
= SHAlloc(strlen(info_dir
)+strlen(file_name
)+strlen(trashinfo_suffix
)+1);
472 if (path
==NULL
) return FALSE
;
473 wsprintfA(path
, "%s%s%s", info_dir
, file_name
, trashinfo_suffix
);
474 TRACE("Trying to create '%s'\n", path
);
475 writer
= open(path
, O_CREAT
|O_WRONLY
|O_TRUNC
|O_EXCL
, 0600);
476 if (writer
==-1) goto error
;
478 write(writer
, trashinfo_header
, strlen(trashinfo_header
));
479 if (!XDG_WriteDesktopStringEntry(writer
, "Path", XDG_URLENCODE
, original_file_name
))
482 GetLocalTime( &curr_time
);
483 wnsprintfA(datebuf
, 200, "%04d-%02d-%02dT%02d:%02d:%02d",
484 curr_time
.wYear
, curr_time
.wMonth
, curr_time
.wDay
,
485 curr_time
.wHour
, curr_time
.wMinute
, curr_time
.wSecond
);
486 if (!XDG_WriteDesktopStringEntry(writer
, "DeletionDate", 0, datebuf
))
503 * Try to create a .trashinfo file. This function will make several attempts with
504 * different filenames. It will return the filename that succeeded or NULL if a file
505 * couldn't be created.
507 static char *create_trashinfo(const char *info_dir
, const char *file_path
)
509 const char *base_name
;
510 char *filename_buffer
;
511 ULONG seed
= GetTickCount();
514 errno
= ENOMEM
; /* out-of-memory is the only case when errno isn't set */
515 base_name
= strrchr(file_path
, '/');
516 if (base_name
== NULL
)
517 base_name
= file_path
;
521 filename_buffer
= SHAlloc(strlen(base_name
)+9+1);
522 if (filename_buffer
== NULL
)
524 lstrcpyA(filename_buffer
, base_name
);
525 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
526 return filename_buffer
;
529 sprintf(filename_buffer
, "%s-%d", base_name
, i
+1);
530 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
531 return filename_buffer
;
534 for (i
=0; i
<1000; i
++)
536 sprintf(filename_buffer
, "%s-%08x", base_name
, RtlRandom(&seed
));
537 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
538 return filename_buffer
;
541 WARN("Couldn't create trashinfo after 1031 tries (errno=%d)\n", errno
);
542 SHFree(filename_buffer
);
546 static void remove_trashinfo_file(const char *info_dir
, const char *base_name
)
548 char *filename_buffer
;
550 filename_buffer
= SHAlloc(lstrlenA(info_dir
)+lstrlenA(base_name
)+lstrlenA(trashinfo_suffix
)+1);
551 if (filename_buffer
== NULL
) return;
552 sprintf(filename_buffer
, "%s%s%s", info_dir
, base_name
, trashinfo_suffix
);
553 unlink(filename_buffer
);
554 SHFree(filename_buffer
);
557 static BOOL
TRASH_MoveFileToBucket(TRASH_BUCKET
*pBucket
, const char *unix_path
)
559 struct stat file_stat
;
560 char *trash_file_name
= NULL
;
561 char *trash_path
= NULL
;
564 if (lstat(unix_path
, &file_stat
)==-1)
566 if (!file_good_for_bucket(pBucket
, &file_stat
))
569 trash_file_name
= create_trashinfo(pBucket
->info_dir
, unix_path
);
570 if (trash_file_name
== NULL
)
573 trash_path
= SHAlloc(strlen(pBucket
->files_dir
)+strlen(trash_file_name
)+1);
574 if (trash_path
== NULL
) goto error
;
575 lstrcpyA(trash_path
, pBucket
->files_dir
);
576 lstrcatA(trash_path
, trash_file_name
);
578 if (rename(unix_path
, trash_path
)==0)
580 TRACE("rename succeeded\n");
584 /* TODO: try to manually move the file */
585 ERR("Couldn't move file\n");
588 remove_trashinfo_file(pBucket
->info_dir
, trash_file_name
);
590 SHFree(trash_file_name
);
595 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
600 TRACE("(%s)\n", debugstr_w(wszPath
));
601 if (!TRASH_EnsureInitialized()) return FALSE
;
602 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
604 result
= TRASH_MoveFileToBucket(home_trash
, unix_path
);
605 heap_free(unix_path
);
609 static HRESULT
TRASH_GetDetails(const TRASH_BUCKET
*bucket
, LPCSTR filename
, WIN32_FIND_DATAW
*data
)
612 XDG_PARSED_FILE
*parsed
= NULL
;
613 char *original_file_name
= NULL
;
614 char *deletion_date
= NULL
;
617 HRESULT ret
= S_FALSE
;
618 LPWSTR original_dos_name
;
619 int suffix_length
= lstrlenA(trashinfo_suffix
);
620 int filename_length
= lstrlenA(filename
);
621 int files_length
= lstrlenA(bucket
->files_dir
);
622 int path_length
= max(lstrlenA(bucket
->info_dir
), files_length
);
624 path
= SHAlloc(path_length
+ filename_length
+ 1);
625 if (path
== NULL
) return E_OUTOFMEMORY
;
626 wsprintfA(path
, "%s%s", bucket
->files_dir
, filename
);
627 path
[path_length
+ filename_length
- suffix_length
] = 0; /* remove the '.trashinfo' */
628 if (lstat(path
, &stats
) == -1)
630 ERR("Error accessing data file for trashinfo %s (errno=%d)\n", filename
, errno
);
634 wsprintfA(path
, "%s%s", bucket
->info_dir
, filename
);
635 fd
= open(path
, O_RDONLY
);
638 ERR("Couldn't open trashinfo file %s (errno=%d)\n", path
, errno
);
642 parsed
= XDG_ParseDesktopFile(fd
);
645 ERR("Parse error in trashinfo file %s\n", path
);
649 original_file_name
= XDG_GetStringValue(parsed
, trashinfo_group
, "Path", XDG_URLENCODE
);
650 if (original_file_name
== NULL
)
652 ERR("No 'Path' entry in trashinfo file\n");
656 ZeroMemory(data
, sizeof(*data
));
657 data
->nFileSizeHigh
= (DWORD
)((LONGLONG
)stats
.st_size
>>32);
658 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
659 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
661 original_dos_name
= wine_get_dos_file_name(original_file_name
);
662 if (original_dos_name
!= NULL
)
664 lstrcpynW(data
->cFileName
, original_dos_name
, MAX_PATH
);
665 heap_free(original_dos_name
);
669 /* show only the file name */
670 char *file
= strrchr(original_file_name
, '/');
672 file
= original_file_name
;
673 MultiByteToWideChar(CP_UNIXCP
, 0, file
, -1, data
->cFileName
, MAX_PATH
);
676 deletion_date
= XDG_GetStringValue(parsed
, trashinfo_group
, "DeletionDate", 0);
682 sscanf(deletion_date
, "%d-%d-%dT%d:%d:%d",
683 &del_time
.tm_year
, &del_time
.tm_mon
, &del_time
.tm_mday
,
684 &del_time
.tm_hour
, &del_time
.tm_min
, &del_time
.tm_sec
);
685 del_time
.tm_year
-= 1900;
687 del_time
.tm_isdst
= -1;
688 del_secs
= mktime(&del_time
);
690 RtlSecondsSince1970ToTime(del_secs
, (LARGE_INTEGER
*)&data
->ftLastAccessTime
);
696 SHFree(original_file_name
);
697 SHFree(deletion_date
);
700 XDG_FreeParsedFile(parsed
);
704 static INT CALLBACK
free_item_callback(void *item
, void *lParam
)
710 static HDPA
enum_bucket_trashinfos(const TRASH_BUCKET
*bucket
, int *count
)
712 HDPA ret
= DPA_Create(32);
713 struct dirent
*entry
;
718 if (ret
== NULL
) goto failed
;
719 dir
= opendir(bucket
->info_dir
);
720 if (dir
== NULL
) goto failed
;
721 while ((entry
= readdir(dir
)) != NULL
)
724 int namelen
= lstrlenA(entry
->d_name
);
725 int suffixlen
= lstrlenA(trashinfo_suffix
);
726 if (namelen
<= suffixlen
||
727 lstrcmpA(entry
->d_name
+namelen
-suffixlen
, trashinfo_suffix
) != 0)
730 filename
= StrDupA(entry
->d_name
);
731 if (filename
== NULL
)
733 if (DPA_InsertPtr(ret
, DPA_APPEND
, filename
) == -1)
743 if (dir
) closedir(dir
);
745 DPA_DestroyCallback(ret
, free_item_callback
, NULL
);
749 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
753 HRESULT err
= E_OUTOFMEMORY
;
757 FIXME("Ignoring path = %s\n", debugstr_w(path
));
759 if (!TRASH_EnsureInitialized()) return E_FAIL
;
760 tinfs
= enum_bucket_trashinfos(home_trash
, &ti_count
);
761 if (tinfs
== NULL
) return E_FAIL
;
762 *pidls
= SHAlloc(sizeof(LPITEMIDLIST
)*ti_count
);
763 if (!*pidls
) goto failed
;
764 for (i
=0; i
<ti_count
; i
++)
766 WIN32_FIND_DATAW data
;
769 filename
= DPA_GetPtr(tinfs
, i
);
770 if (FAILED(err
= TRASH_GetDetails(home_trash
, filename
, &data
)))
774 if (FAILED(err
= TRASH_CreateSimplePIDL(filename
, &data
, &(*pidls
)[pos
])))
779 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
785 for (j
=0; j
<pos
; j
++)
789 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
794 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
){
795 int suffix_length
= strlen(trashinfo_suffix
);
796 LPCSHITEMID id
= &(pidl
->mkid
);
797 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
798 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
800 WIN32_FIND_DATAW data
;
803 TRACE("(%p)\n",pidl
);
804 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
806 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
809 TRASH_UnpackItemID(id
,&data
);
810 restore_path
= wine_get_unix_file_name(data
.cFileName
);
811 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
812 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
813 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
814 if(!rename(file_path
,restore_path
))
816 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
817 if(unlink(file_path
))
818 WARN("failed to delete the trashinfo file %s\n",filename
);
821 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
823 heap_free(restore_path
);
827 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
829 int suffix_length
= strlen(trashinfo_suffix
);
831 LPCSHITEMID id
= &(pidl
->mkid
);
832 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
833 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
836 TRACE("(%p)\n",pidl
);
837 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
839 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
842 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
843 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
844 if(unlink(file_path
))
845 WARN("failed to delete the trashinfo file %s\n",filename
);
846 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
847 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
848 if(unlink(file_path
))
849 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
854 #endif /* __APPLE__ */