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
30 #include <sys/types.h>
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
34 #ifdef HAVE_SYS_MOUNT_H
35 # include <sys/mount.h>
54 #include "wine/debug.h"
55 #include "shell32_main.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(trash
);
61 * The item ID of a trashed element is built as follows:
62 * NUL byte - in most PIDLs the first byte is the type so we keep it constant
63 * WIN32_FIND_DATAW structure - with data about original file attributes
64 * bucket name - currently only an empty string meaning the home bucket is supported
65 * trash file name - a NUL-terminated string
67 static HRESULT
TRASH_CreateSimplePIDL(LPCSTR filename
, const WIN32_FIND_DATAW
*data
, LPITEMIDLIST
*pidlOut
)
69 LPITEMIDLIST pidl
= SHAlloc(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1+2);
73 pidl
->mkid
.cb
= (USHORT
)(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1);
74 pidl
->mkid
.abID
[0] = 0;
75 memcpy(pidl
->mkid
.abID
+1, data
, sizeof(WIN32_FIND_DATAW
));
76 pidl
->mkid
.abID
[1+sizeof(WIN32_FIND_DATAW
)] = 0;
77 lstrcpyA((LPSTR
)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1), filename
);
78 *(USHORT
*)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1) = 0;
83 /***********************************************************************
84 * TRASH_UnpackItemID [Internal]
87 * Extract the information stored in an Item ID. The WIN32_FIND_DATA contains
88 * the information about the original file. The data->ftLastAccessTime contains
92 * [I] id : the ID of the item
93 * [O] data : the WIN32_FIND_DATA of the original file. Can be NULL is not needed
95 HRESULT
TRASH_UnpackItemID(LPCSHITEMID id
, WIN32_FIND_DATAW
*data
)
97 if (id
->cb
< 2+1+sizeof(WIN32_FIND_DATAW
)+2)
99 if (id
->abID
[0] != 0 || id
->abID
[1+sizeof(WIN32_FIND_DATAW
)] != 0)
101 if (memchr(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+1, 0, id
->cb
-(2+1+sizeof(WIN32_FIND_DATAW
)+1)) == NULL
)
105 *data
= *(const WIN32_FIND_DATAW
*)(id
->abID
+1);
111 static char *TRASH_GetTrashPath(const char *unix_path
, const char **base_name
)
113 struct statfs stfs
, home_stfs
;
114 struct passwd
*user
= getpwuid(geteuid());
118 if (statfs(unix_path
, &stfs
) == -1)
120 if (statfs(user
->pw_dir
, &home_stfs
) == -1)
123 *base_name
= strrchr(unix_path
, '/');
125 *base_name
= unix_path
;
128 name_size
= lstrlenA(*base_name
);
130 /* If the file exists on the same volume as the user's home directory,
131 * we can use the User domain Trash folder. Otherwise, we have to use
132 * <volume>/.Trashes/<uid>.
134 if (memcmp(&stfs
.f_fsid
, &home_stfs
.f_fsid
, sizeof(fsid_t
)) == 0)
136 size_t home_size
= lstrlenA(user
->pw_dir
);
137 trash_path
= heap_alloc(home_size
+ sizeof("/.Trash/") + name_size
);
140 memcpy(trash_path
, user
->pw_dir
, home_size
);
141 memcpy(trash_path
+home_size
, "/.Trash", sizeof("/.Trash"));
145 size_t vol_size
= lstrlenA(stfs
.f_mntonname
);
146 /* 10 for the maximum length of a 32-bit integer + 1 for the \0 */
147 size_t trash_size
= vol_size
+ sizeof("/.Trashes/") + 10 + 1 + name_size
+ 1;
148 trash_path
= heap_alloc(trash_size
);
151 snprintf(trash_path
, trash_size
, "%s/.Trashes/%u", stfs
.f_mntonname
, geteuid());
156 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
158 char *unix_path
, *trash_path
;
159 const char *base_name
;
163 TRACE("(%s)\n", debugstr_w(wszPath
));
165 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
167 if (!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
169 heap_free(unix_path
);
172 can_trash
= stat(trash_path
, &st
) == 0;
173 if (!can_trash
&& errno
== ENOENT
)
175 /* Recursively create the Trash folder. */
176 char *p
= trash_path
;
178 while ((p
= strchr(p
, '/')) != NULL
)
181 if (mkdir(trash_path
, 0755) == -1 && errno
!= EEXIST
)
183 heap_free(unix_path
);
184 heap_free(trash_path
);
191 heap_free(unix_path
);
192 heap_free(trash_path
);
196 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
198 char *unix_path
, *trash_path
;
199 const char *base_name
;
202 TRACE("(%s)\n", debugstr_w(wszPath
));
203 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
205 if (!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
207 heap_free(unix_path
);
211 lstrcatA(trash_path
, "/");
212 lstrcatA(trash_path
, base_name
);
214 res
= rename(unix_path
, trash_path
);
216 heap_free(unix_path
);
217 heap_free(trash_path
);
222 * - set file deletion time
223 * - set original file location
225 HRESULT
TRASH_GetDetails(const char *trash_path
, const char *name
, WIN32_FIND_DATAW
*data
)
229 int trash_path_length
= lstrlenA(trash_path
);
230 int name_length
= lstrlenA(name
);
231 char *path
= SHAlloc(trash_path_length
+1+name_length
+1);
235 if(!once
++) FIXME("semi-stub\n");
237 if(!path
) return E_OUTOFMEMORY
;
238 memcpy(path
, trash_path
, trash_path_length
);
239 path
[trash_path_length
] = '/';
240 memcpy(path
+trash_path_length
+1, name
, name_length
+1);
242 ret
= lstat(path
, &stats
);
244 if(ret
== -1) return S_FALSE
;
245 memset(data
, 0, sizeof(*data
));
246 data
->nFileSizeHigh
= stats
.st_size
>>32;
247 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
248 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
250 if(!MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, data
->cFileName
, MAX_PATH
))
255 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
257 WCHAR volume_path
[MAX_PATH
];
258 char *unix_path
, *trash_path
;
259 const char *base_name
;
260 struct dirent
*entry
;
266 TRACE("(%s %p %p)\n", debugstr_w(path
), pidls
, count
);
269 FIXME("All trashes enumeration not supported\n");
270 volume_path
[0] = 'C';
271 volume_path
[1] = ':';
274 if(!GetVolumePathNameW(path
, volume_path
, MAX_PATH
))
278 if(!(unix_path
= wine_get_unix_file_name(volume_path
)))
279 return E_OUTOFMEMORY
;
281 if(!(trash_path
= TRASH_GetTrashPath(unix_path
, &base_name
)))
282 return E_OUTOFMEMORY
;
284 if(!(dir
= opendir(trash_path
))) return E_FAIL
;
285 ret
= heap_alloc(ret_size
* sizeof(*ret
));
288 return E_OUTOFMEMORY
;
290 while((entry
= readdir(dir
))) {
291 WIN32_FIND_DATAW data
;
293 if(!lstrcmpA(entry
->d_name
, ".") || !lstrcmpA(entry
->d_name
, ".." )
294 || !lstrcmpA(entry
->d_name
, ".DS_Store"))
298 LPITEMIDLIST
*resized
;
300 resized
= heap_realloc(ret
, ret_size
* sizeof(*ret
));
301 if(!resized
) hr
= E_OUTOFMEMORY
;
306 hr
= TRASH_GetDetails(trash_path
, entry
->d_name
, &data
);
307 if(hr
== S_FALSE
) continue;
310 hr
= TRASH_CreateSimplePIDL(entry
->d_name
, &data
, ret
+i
);
312 while(i
>0) SHFree(ret
+(--i
));
321 *pidls
= SHAlloc(sizeof(**pidls
) * i
);
323 while(i
>0) SHFree(ret
+(--i
));
325 return E_OUTOFMEMORY
;
328 for(i
--; i
>=0; i
--) (*pidls
)[i
] = ret
[i
];
333 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
)
339 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
345 #else /* __APPLE__ */
347 static CRITICAL_SECTION TRASH_Creating
;
348 static CRITICAL_SECTION_DEBUG TRASH_Creating_Debug
=
350 0, 0, &TRASH_Creating
,
351 { &TRASH_Creating_Debug
.ProcessLocksList
,
352 &TRASH_Creating_Debug
.ProcessLocksList
},
353 0, 0, { (DWORD_PTR
)__FILE__
": TRASH_Creating"}
355 static CRITICAL_SECTION TRASH_Creating
= { &TRASH_Creating_Debug
, -1, 0, 0, 0, 0 };
357 static const char trashinfo_suffix
[] = ".trashinfo";
358 static const char trashinfo_header
[] = "[Trash Info]\n";
359 static const char trashinfo_group
[] = "Trash Info";
368 static TRASH_BUCKET
*home_trash
=NULL
;
370 static char *init_home_dir(const char *subpath
)
372 char *path
= XDG_BuildPath(XDG_DATA_HOME
, subpath
);
373 if (path
== NULL
) return NULL
;
374 if (!XDG_MakeDirs(path
))
376 ERR("Couldn't create directory %s (errno=%d). Trash won't be available\n", debugstr_a(path
), errno
);
383 static TRASH_BUCKET
*TRASH_CreateHomeBucket(void)
385 TRASH_BUCKET
*bucket
;
386 struct stat trash_stat
;
387 char *trash_path
= NULL
;
389 bucket
= SHAlloc(sizeof(TRASH_BUCKET
));
395 memset(bucket
, 0, sizeof(*bucket
));
396 bucket
->info_dir
= init_home_dir("Trash/info/");
397 if (bucket
->info_dir
== NULL
) goto error
;
398 bucket
->files_dir
= init_home_dir("Trash/files/");
399 if (bucket
->files_dir
== NULL
) goto error
;
401 trash_path
= XDG_BuildPath(XDG_DATA_HOME
, "Trash/");
402 if (stat(trash_path
, &trash_stat
) == -1)
404 bucket
->device
= trash_stat
.st_dev
;
411 SHFree(bucket
->info_dir
);
412 SHFree(bucket
->files_dir
);
418 static BOOL
TRASH_EnsureInitialized(void)
420 if (home_trash
== NULL
)
422 EnterCriticalSection(&TRASH_Creating
);
423 if (home_trash
== NULL
)
424 home_trash
= TRASH_CreateHomeBucket();
425 LeaveCriticalSection(&TRASH_Creating
);
428 if (home_trash
== NULL
)
430 ERR("Couldn't initialize home trash (errno=%d)\n", errno
);
436 static BOOL
file_good_for_bucket(const TRASH_BUCKET
*pBucket
, const struct stat
*file_stat
)
438 if (pBucket
->device
!= file_stat
->st_dev
)
443 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
445 struct stat file_stat
;
449 TRACE("(%s)\n", debugstr_w(wszPath
));
450 if (!TRASH_EnsureInitialized()) return FALSE
;
451 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
453 ret
= lstat(unix_path
, &file_stat
);
454 heap_free(unix_path
);
457 return file_good_for_bucket(home_trash
, &file_stat
);
461 * Try to create a single .trashinfo file. Return TRUE if successful, else FALSE
463 static BOOL
try_create_trashinfo_file(const char *info_dir
, const char *file_name
,
464 const char *original_file_name
)
466 SYSTEMTIME curr_time
;
468 char *path
= SHAlloc(strlen(info_dir
)+strlen(file_name
)+strlen(trashinfo_suffix
)+1);
471 if (path
==NULL
) return FALSE
;
472 wsprintfA(path
, "%s%s%s", info_dir
, file_name
, trashinfo_suffix
);
473 TRACE("Trying to create '%s'\n", path
);
474 writer
= open(path
, O_CREAT
|O_WRONLY
|O_TRUNC
|O_EXCL
, 0600);
475 if (writer
==-1) goto error
;
477 write(writer
, trashinfo_header
, strlen(trashinfo_header
));
478 if (!XDG_WriteDesktopStringEntry(writer
, "Path", XDG_URLENCODE
, original_file_name
))
481 GetLocalTime( &curr_time
);
482 wnsprintfA(datebuf
, 200, "%04d-%02d-%02dT%02d:%02d:%02d",
483 curr_time
.wYear
, curr_time
.wMonth
, curr_time
.wDay
,
484 curr_time
.wHour
, curr_time
.wMinute
, curr_time
.wSecond
);
485 if (!XDG_WriteDesktopStringEntry(writer
, "DeletionDate", 0, datebuf
))
502 * Try to create a .trashinfo file. This function will make several attempts with
503 * different filenames. It will return the filename that succeeded or NULL if a file
504 * couldn't be created.
506 static char *create_trashinfo(const char *info_dir
, const char *file_path
)
508 const char *base_name
;
509 char *filename_buffer
;
510 ULONG seed
= GetTickCount();
513 errno
= ENOMEM
; /* out-of-memory is the only case when errno isn't set */
514 base_name
= strrchr(file_path
, '/');
515 if (base_name
== NULL
)
516 base_name
= file_path
;
520 filename_buffer
= SHAlloc(strlen(base_name
)+9+1);
521 if (filename_buffer
== NULL
)
523 lstrcpyA(filename_buffer
, base_name
);
524 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
525 return filename_buffer
;
528 sprintf(filename_buffer
, "%s-%d", base_name
, i
+1);
529 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
530 return filename_buffer
;
533 for (i
=0; i
<1000; i
++)
535 sprintf(filename_buffer
, "%s-%08x", base_name
, RtlRandom(&seed
));
536 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
537 return filename_buffer
;
540 WARN("Couldn't create trashinfo after 1031 tries (errno=%d)\n", errno
);
541 SHFree(filename_buffer
);
545 static void remove_trashinfo_file(const char *info_dir
, const char *base_name
)
547 char *filename_buffer
;
549 filename_buffer
= SHAlloc(lstrlenA(info_dir
)+lstrlenA(base_name
)+lstrlenA(trashinfo_suffix
)+1);
550 if (filename_buffer
== NULL
) return;
551 sprintf(filename_buffer
, "%s%s%s", info_dir
, base_name
, trashinfo_suffix
);
552 unlink(filename_buffer
);
553 SHFree(filename_buffer
);
556 static BOOL
TRASH_MoveFileToBucket(TRASH_BUCKET
*pBucket
, const char *unix_path
)
558 struct stat file_stat
;
559 char *trash_file_name
= NULL
;
560 char *trash_path
= NULL
;
563 if (lstat(unix_path
, &file_stat
)==-1)
565 if (!file_good_for_bucket(pBucket
, &file_stat
))
568 trash_file_name
= create_trashinfo(pBucket
->info_dir
, unix_path
);
569 if (trash_file_name
== NULL
)
572 trash_path
= SHAlloc(strlen(pBucket
->files_dir
)+strlen(trash_file_name
)+1);
573 if (trash_path
== NULL
) goto error
;
574 lstrcpyA(trash_path
, pBucket
->files_dir
);
575 lstrcatA(trash_path
, trash_file_name
);
577 if (rename(unix_path
, trash_path
)==0)
579 TRACE("rename succeeded\n");
583 /* TODO: try to manually move the file */
584 ERR("Couldn't move file\n");
587 remove_trashinfo_file(pBucket
->info_dir
, trash_file_name
);
589 SHFree(trash_file_name
);
594 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
599 TRACE("(%s)\n", debugstr_w(wszPath
));
600 if (!TRASH_EnsureInitialized()) return FALSE
;
601 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
603 result
= TRASH_MoveFileToBucket(home_trash
, unix_path
);
604 heap_free(unix_path
);
608 static HRESULT
TRASH_GetDetails(const TRASH_BUCKET
*bucket
, LPCSTR filename
, WIN32_FIND_DATAW
*data
)
611 XDG_PARSED_FILE
*parsed
= NULL
;
612 char *original_file_name
= NULL
;
613 char *deletion_date
= NULL
;
616 HRESULT ret
= S_FALSE
;
617 LPWSTR original_dos_name
;
618 int suffix_length
= lstrlenA(trashinfo_suffix
);
619 int filename_length
= lstrlenA(filename
);
620 int files_length
= lstrlenA(bucket
->files_dir
);
621 int path_length
= max(lstrlenA(bucket
->info_dir
), files_length
);
623 path
= SHAlloc(path_length
+ filename_length
+ 1);
624 if (path
== NULL
) return E_OUTOFMEMORY
;
625 wsprintfA(path
, "%s%s", bucket
->files_dir
, filename
);
626 path
[path_length
+ filename_length
- suffix_length
] = 0; /* remove the '.trashinfo' */
627 if (lstat(path
, &stats
) == -1)
629 ERR("Error accessing data file for trashinfo %s (errno=%d)\n", filename
, errno
);
633 wsprintfA(path
, "%s%s", bucket
->info_dir
, filename
);
634 fd
= open(path
, O_RDONLY
);
637 ERR("Couldn't open trashinfo file %s (errno=%d)\n", path
, errno
);
641 parsed
= XDG_ParseDesktopFile(fd
);
644 ERR("Parse error in trashinfo file %s\n", path
);
648 original_file_name
= XDG_GetStringValue(parsed
, trashinfo_group
, "Path", XDG_URLENCODE
);
649 if (original_file_name
== NULL
)
651 ERR("No 'Path' entry in trashinfo file\n");
655 ZeroMemory(data
, sizeof(*data
));
656 data
->nFileSizeHigh
= (DWORD
)((LONGLONG
)stats
.st_size
>>32);
657 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
658 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
660 original_dos_name
= wine_get_dos_file_name(original_file_name
);
661 if (original_dos_name
!= NULL
)
663 lstrcpynW(data
->cFileName
, original_dos_name
, MAX_PATH
);
664 SHFree(original_dos_name
);
668 /* show only the file name */
669 char *file
= strrchr(original_file_name
, '/');
671 file
= original_file_name
;
672 MultiByteToWideChar(CP_UNIXCP
, 0, file
, -1, data
->cFileName
, MAX_PATH
);
675 deletion_date
= XDG_GetStringValue(parsed
, trashinfo_group
, "DeletionDate", 0);
681 sscanf(deletion_date
, "%d-%d-%dT%d:%d:%d",
682 &del_time
.tm_year
, &del_time
.tm_mon
, &del_time
.tm_mday
,
683 &del_time
.tm_hour
, &del_time
.tm_min
, &del_time
.tm_sec
);
684 del_time
.tm_year
-= 1900;
686 del_time
.tm_isdst
= -1;
687 del_secs
= mktime(&del_time
);
689 RtlSecondsSince1970ToTime(del_secs
, (LARGE_INTEGER
*)&data
->ftLastAccessTime
);
695 SHFree(original_file_name
);
696 SHFree(deletion_date
);
699 XDG_FreeParsedFile(parsed
);
703 static INT CALLBACK
free_item_callback(void *item
, void *lParam
)
709 static HDPA
enum_bucket_trashinfos(const TRASH_BUCKET
*bucket
, int *count
)
711 HDPA ret
= DPA_Create(32);
712 struct dirent
*entry
;
717 if (ret
== NULL
) goto failed
;
718 dir
= opendir(bucket
->info_dir
);
719 if (dir
== NULL
) goto failed
;
720 while ((entry
= readdir(dir
)) != NULL
)
723 int namelen
= lstrlenA(entry
->d_name
);
724 int suffixlen
= lstrlenA(trashinfo_suffix
);
725 if (namelen
<= suffixlen
||
726 lstrcmpA(entry
->d_name
+namelen
-suffixlen
, trashinfo_suffix
) != 0)
729 filename
= StrDupA(entry
->d_name
);
730 if (filename
== NULL
)
732 if (DPA_InsertPtr(ret
, DPA_APPEND
, filename
) == -1)
742 if (dir
) closedir(dir
);
744 DPA_DestroyCallback(ret
, free_item_callback
, NULL
);
748 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
752 HRESULT err
= E_OUTOFMEMORY
;
756 FIXME("Ignoring path = %s\n", debugstr_w(path
));
758 if (!TRASH_EnsureInitialized()) return E_FAIL
;
759 tinfs
= enum_bucket_trashinfos(home_trash
, &ti_count
);
760 if (tinfs
== NULL
) return E_FAIL
;
761 *pidls
= SHAlloc(sizeof(LPITEMIDLIST
)*ti_count
);
762 if (!*pidls
) goto failed
;
763 for (i
=0; i
<ti_count
; i
++)
765 WIN32_FIND_DATAW data
;
768 filename
= DPA_GetPtr(tinfs
, i
);
769 if (FAILED(err
= TRASH_GetDetails(home_trash
, filename
, &data
)))
773 if (FAILED(err
= TRASH_CreateSimplePIDL(filename
, &data
, &(*pidls
)[pos
])))
778 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
784 for (j
=0; j
<pos
; j
++)
788 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
793 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
){
794 int suffix_length
= strlen(trashinfo_suffix
);
795 LPCSHITEMID id
= &(pidl
->mkid
);
796 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
797 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
799 WIN32_FIND_DATAW data
;
802 TRACE("(%p)\n",pidl
);
803 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
805 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
808 TRASH_UnpackItemID(id
,&data
);
809 restore_path
= wine_get_unix_file_name(data
.cFileName
);
810 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
811 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
812 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
813 if(!rename(file_path
,restore_path
))
815 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
816 if(unlink(file_path
))
817 WARN("failed to delete the trashinfo file %s\n",filename
);
820 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
822 heap_free(restore_path
);
826 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
828 int suffix_length
= strlen(trashinfo_suffix
);
830 LPCSHITEMID id
= &(pidl
->mkid
);
831 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
832 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
835 TRACE("(%p)\n",pidl
);
836 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
838 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
841 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
842 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
843 if(unlink(file_path
))
844 WARN("failed to delete the trashinfo file %s\n",filename
);
845 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
846 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
847 if(unlink(file_path
))
848 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
853 #endif /* __APPLE__ */