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
25 #ifdef HAVE_CORESERVICES_CORESERVICES_H
26 #define GetCurrentThread MacGetCurrentThread
27 #define LoadResource MacLoadResource
28 #include <CoreServices/CoreServices.h>
29 #undef GetCurrentThread
39 #ifdef HAVE_SYS_STAT_H
40 # include <sys/stat.h>
42 #include <sys/types.h>
57 #include "wine/debug.h"
58 #include "shell32_main.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(trash
);
64 * The item ID of a trashed element is built as follows:
65 * NUL byte - in most PIDLs the first byte is the type so we keep it constant
66 * WIN32_FIND_DATAW structure - with data about original file attributes
67 * bucket name - currently only an empty string meaning the home bucket is supported
68 * trash file name - a NUL-terminated string
70 static HRESULT
TRASH_CreateSimplePIDL(LPCSTR filename
, const WIN32_FIND_DATAW
*data
, LPITEMIDLIST
*pidlOut
)
72 LPITEMIDLIST pidl
= SHAlloc(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1+2);
76 pidl
->mkid
.cb
= (USHORT
)(2+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1);
77 pidl
->mkid
.abID
[0] = 0;
78 memcpy(pidl
->mkid
.abID
+1, data
, sizeof(WIN32_FIND_DATAW
));
79 pidl
->mkid
.abID
[1+sizeof(WIN32_FIND_DATAW
)] = 0;
80 lstrcpyA((LPSTR
)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1), filename
);
81 *(USHORT
*)(pidl
->mkid
.abID
+1+sizeof(WIN32_FIND_DATAW
)+1+lstrlenA(filename
)+1) = 0;
86 /***********************************************************************
87 * TRASH_UnpackItemID [Internal]
90 * Extract the information stored in an Item ID. The WIN32_FIND_DATA contains
91 * the information about the original file. The data->ftLastAccessTime contains
95 * [I] id : the ID of the item
96 * [O] data : the WIN32_FIND_DATA of the original file. Can be NULL is not needed
98 HRESULT
TRASH_UnpackItemID(LPCSHITEMID id
, WIN32_FIND_DATAW
*data
)
100 if (id
->cb
< 2+1+sizeof(WIN32_FIND_DATAW
)+2)
102 if (id
->abID
[0] != 0 || id
->abID
[1+sizeof(WIN32_FIND_DATAW
)] != 0)
104 if (memchr(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+1, 0, id
->cb
-(2+1+sizeof(WIN32_FIND_DATAW
)+1)) == NULL
)
108 *data
= *(const WIN32_FIND_DATAW
*)(id
->abID
+1);
112 #ifdef HAVE_CORESERVICES_CORESERVICES_H
114 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
119 FSCatalogInfo catalogInfo
;
121 TRACE("(%s)\n", debugstr_w(wszPath
));
122 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
125 status
= FSPathMakeRef((UInt8
*)unix_path
, &ref
, NULL
);
126 HeapFree(GetProcessHeap(), 0, unix_path
);
128 status
= FSGetCatalogInfo(&ref
, kFSCatInfoVolume
, &catalogInfo
, NULL
,
131 status
= FSFindFolder(catalogInfo
.volume
, kTrashFolderType
,
132 kCreateFolder
, &ref
);
134 return (status
== noErr
);
137 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
142 TRACE("(%s)\n", debugstr_w(wszPath
));
143 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
146 status
= FSPathMoveObjectToTrashSync(unix_path
, NULL
, kFSFileOperationSkipPreflight
);
148 HeapFree(GetProcessHeap(), 0, unix_path
);
149 return (status
== noErr
);
153 * - set file deletion time
154 * - set original file location
156 HRESULT
TRASH_GetDetails(const char *trash_path
, const char *name
, WIN32_FIND_DATAW
*data
)
160 int trash_path_length
= lstrlenA(trash_path
);
161 int name_length
= lstrlenA(name
);
162 char *path
= SHAlloc(trash_path_length
+1+name_length
+1);
166 if(!once
++) FIXME("semi-stub\n");
168 if(!path
) return E_OUTOFMEMORY
;
169 memcpy(path
, trash_path
, trash_path_length
);
170 path
[trash_path_length
] = '/';
171 memcpy(path
+trash_path_length
+1, name
, name_length
+1);
173 ret
= lstat(path
, &stats
);
174 HeapFree(GetProcessHeap(), 0, path
);
175 if(ret
== -1) return S_FALSE
;
176 memset(data
, 0, sizeof(*data
));
177 data
->nFileSizeHigh
= stats
.st_size
>>32;
178 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
179 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
181 if(!MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, data
->cFileName
, MAX_PATH
))
186 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
188 WCHAR volume_path
[MAX_PATH
];
189 char *unix_path
, trash_path
[MAX_PATH
];
190 FSCatalogInfo catalog_info
;
193 struct dirent
*entry
;
199 TRACE("(%s %p %p)\n", debugstr_w(path
), pidls
, count
);
202 FIXME("All trashes enumeration not supported\n");
203 volume_path
[0] = 'C';
204 volume_path
[1] = ':';
207 if(!GetVolumePathNameW(path
, volume_path
, MAX_PATH
))
211 if(!(unix_path
= wine_get_unix_file_name(volume_path
)))
212 return E_OUTOFMEMORY
;
214 status
= FSPathMakeRef((UInt8
*)unix_path
, &ref
, NULL
);
215 HeapFree(GetProcessHeap(), 0, unix_path
);
216 if(status
!= noErr
) return E_FAIL
;
217 status
= FSGetCatalogInfo(&ref
, kFSCatInfoVolume
, &catalog_info
, NULL
, NULL
, NULL
);
218 if(status
!= noErr
) return E_FAIL
;
219 status
= FSFindFolder(catalog_info
.volume
, kTrashFolderType
, kCreateFolder
, &ref
);
220 if(status
!= noErr
) return E_FAIL
;
221 status
= FSRefMakePath(&ref
, (UInt8
*)trash_path
, MAX_PATH
);
222 if(status
!= noErr
) return E_FAIL
;
224 if(!(dir
= opendir(trash_path
))) return E_FAIL
;
225 ret
= HeapAlloc(GetProcessHeap(), 0, ret_size
* sizeof(*ret
));
228 return E_OUTOFMEMORY
;
230 while((entry
= readdir(dir
))) {
231 WIN32_FIND_DATAW data
;
233 if(!lstrcmpA(entry
->d_name
, ".") || !lstrcmpA(entry
->d_name
, ".." )
234 || !lstrcmpA(entry
->d_name
, ".DS_Store"))
238 LPITEMIDLIST
*resized
;
240 resized
= HeapReAlloc(GetProcessHeap(), 0, ret
, ret_size
* sizeof(*ret
));
241 if(!resized
) hr
= E_OUTOFMEMORY
;
246 hr
= TRASH_GetDetails(trash_path
, entry
->d_name
, &data
);
247 if(hr
== S_FALSE
) continue;
250 hr
= TRASH_CreateSimplePIDL(entry
->d_name
, &data
, ret
+i
);
252 while(i
>0) SHFree(ret
+(--i
));
253 HeapFree(GetProcessHeap(), 0, ret
);
261 *pidls
= SHAlloc(sizeof(**pidls
) * i
);
263 while(i
>0) SHFree(ret
+(--i
));
264 HeapFree(GetProcessHeap(), 0, ret
);
265 return E_OUTOFMEMORY
;
268 for(i
--; i
>=0; i
--) (*pidls
)[i
] = ret
[i
];
269 HeapFree(GetProcessHeap(), 0, ret
);
273 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
)
279 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
285 #else /* HAVE_CORESERVICES_CORESERVICES_H */
287 static CRITICAL_SECTION TRASH_Creating
;
288 static CRITICAL_SECTION_DEBUG TRASH_Creating_Debug
=
290 0, 0, &TRASH_Creating
,
291 { &TRASH_Creating_Debug
.ProcessLocksList
,
292 &TRASH_Creating_Debug
.ProcessLocksList
},
293 0, 0, { (DWORD_PTR
)__FILE__
": TRASH_Creating"}
295 static CRITICAL_SECTION TRASH_Creating
= { &TRASH_Creating_Debug
, -1, 0, 0, 0, 0 };
297 static const char trashinfo_suffix
[] = ".trashinfo";
298 static const char trashinfo_header
[] = "[Trash Info]\n";
299 static const char trashinfo_group
[] = "Trash Info";
308 static TRASH_BUCKET
*home_trash
=NULL
;
310 static char *init_home_dir(const char *subpath
)
312 char *path
= XDG_BuildPath(XDG_DATA_HOME
, subpath
);
313 if (path
== NULL
) return NULL
;
314 if (!XDG_MakeDirs(path
))
316 ERR("Couldn't create directory %s (errno=%d). Trash won't be available\n", debugstr_a(path
), errno
);
323 static TRASH_BUCKET
*TRASH_CreateHomeBucket(void)
325 TRASH_BUCKET
*bucket
;
326 struct stat trash_stat
;
327 char *trash_path
= NULL
;
329 bucket
= SHAlloc(sizeof(TRASH_BUCKET
));
335 memset(bucket
, 0, sizeof(*bucket
));
336 bucket
->info_dir
= init_home_dir("Trash/info/");
337 if (bucket
->info_dir
== NULL
) goto error
;
338 bucket
->files_dir
= init_home_dir("Trash/files/");
339 if (bucket
->files_dir
== NULL
) goto error
;
341 trash_path
= XDG_BuildPath(XDG_DATA_HOME
, "Trash/");
342 if (stat(trash_path
, &trash_stat
) == -1)
344 bucket
->device
= trash_stat
.st_dev
;
351 SHFree(bucket
->info_dir
);
352 SHFree(bucket
->files_dir
);
358 static BOOL
TRASH_EnsureInitialized(void)
360 if (home_trash
== NULL
)
362 EnterCriticalSection(&TRASH_Creating
);
363 if (home_trash
== NULL
)
364 home_trash
= TRASH_CreateHomeBucket();
365 LeaveCriticalSection(&TRASH_Creating
);
368 if (home_trash
== NULL
)
370 ERR("Couldn't initialize home trash (errno=%d)\n", errno
);
376 static BOOL
file_good_for_bucket(const TRASH_BUCKET
*pBucket
, const struct stat
*file_stat
)
378 if (pBucket
->device
!= file_stat
->st_dev
)
383 BOOL
TRASH_CanTrashFile(LPCWSTR wszPath
)
385 struct stat file_stat
;
388 TRACE("(%s)\n", debugstr_w(wszPath
));
389 if (!TRASH_EnsureInitialized()) return FALSE
;
390 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
392 if (lstat(unix_path
, &file_stat
)==-1)
394 HeapFree(GetProcessHeap(), 0, unix_path
);
397 HeapFree(GetProcessHeap(), 0, unix_path
);
398 return file_good_for_bucket(home_trash
, &file_stat
);
402 * Try to create a single .trashinfo file. Return TRUE if successful, else FALSE
404 static BOOL
try_create_trashinfo_file(const char *info_dir
, const char *file_name
,
405 const char *original_file_name
)
407 SYSTEMTIME curr_time
;
409 char *path
= SHAlloc(strlen(info_dir
)+strlen(file_name
)+strlen(trashinfo_suffix
)+1);
412 if (path
==NULL
) return FALSE
;
413 wsprintfA(path
, "%s%s%s", info_dir
, file_name
, trashinfo_suffix
);
414 TRACE("Trying to create '%s'\n", path
);
415 writer
= open(path
, O_CREAT
|O_WRONLY
|O_TRUNC
|O_EXCL
, 0600);
416 if (writer
==-1) goto error
;
418 write(writer
, trashinfo_header
, strlen(trashinfo_header
));
419 if (!XDG_WriteDesktopStringEntry(writer
, "Path", XDG_URLENCODE
, original_file_name
))
422 GetLocalTime( &curr_time
);
423 wnsprintfA(datebuf
, 200, "%04d-%02d-%02dT%02d:%02d:%02d",
424 curr_time
.wYear
, curr_time
.wMonth
, curr_time
.wDay
,
425 curr_time
.wHour
, curr_time
.wMinute
, curr_time
.wSecond
);
426 if (!XDG_WriteDesktopStringEntry(writer
, "DeletionDate", 0, datebuf
))
443 * Try to create a .trashinfo file. This function will make several attempts with
444 * different filenames. It will return the filename that succeeded or NULL if a file
445 * couldn't be created.
447 static char *create_trashinfo(const char *info_dir
, const char *file_path
)
449 const char *base_name
;
450 char *filename_buffer
;
451 ULONG seed
= GetTickCount();
454 errno
= ENOMEM
; /* out-of-memory is the only case when errno isn't set */
455 base_name
= strrchr(file_path
, '/');
456 if (base_name
== NULL
)
457 base_name
= file_path
;
461 filename_buffer
= SHAlloc(strlen(base_name
)+9+1);
462 if (filename_buffer
== NULL
)
464 lstrcpyA(filename_buffer
, base_name
);
465 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
466 return filename_buffer
;
469 sprintf(filename_buffer
, "%s-%d", base_name
, i
+1);
470 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
471 return filename_buffer
;
474 for (i
=0; i
<1000; i
++)
476 sprintf(filename_buffer
, "%s-%08x", base_name
, RtlRandom(&seed
));
477 if (try_create_trashinfo_file(info_dir
, filename_buffer
, file_path
))
478 return filename_buffer
;
481 WARN("Couldn't create trashinfo after 1031 tries (errno=%d)\n", errno
);
482 SHFree(filename_buffer
);
486 static void remove_trashinfo_file(const char *info_dir
, const char *base_name
)
488 char *filename_buffer
;
490 filename_buffer
= SHAlloc(lstrlenA(info_dir
)+lstrlenA(base_name
)+lstrlenA(trashinfo_suffix
)+1);
491 if (filename_buffer
== NULL
) return;
492 sprintf(filename_buffer
, "%s%s%s", info_dir
, base_name
, trashinfo_suffix
);
493 unlink(filename_buffer
);
494 SHFree(filename_buffer
);
497 static BOOL
TRASH_MoveFileToBucket(TRASH_BUCKET
*pBucket
, const char *unix_path
)
499 struct stat file_stat
;
500 char *trash_file_name
= NULL
;
501 char *trash_path
= NULL
;
504 if (lstat(unix_path
, &file_stat
)==-1)
506 if (!file_good_for_bucket(pBucket
, &file_stat
))
509 trash_file_name
= create_trashinfo(pBucket
->info_dir
, unix_path
);
510 if (trash_file_name
== NULL
)
513 trash_path
= SHAlloc(strlen(pBucket
->files_dir
)+strlen(trash_file_name
)+1);
514 if (trash_path
== NULL
) goto error
;
515 lstrcpyA(trash_path
, pBucket
->files_dir
);
516 lstrcatA(trash_path
, trash_file_name
);
518 if (rename(unix_path
, trash_path
)==0)
520 TRACE("rename succeeded\n");
524 /* TODO: try to manually move the file */
525 ERR("Couldn't move file\n");
528 remove_trashinfo_file(pBucket
->info_dir
, trash_file_name
);
530 SHFree(trash_file_name
);
535 BOOL
TRASH_TrashFile(LPCWSTR wszPath
)
540 TRACE("(%s)\n", debugstr_w(wszPath
));
541 if (!TRASH_EnsureInitialized()) return FALSE
;
542 if (!(unix_path
= wine_get_unix_file_name(wszPath
)))
544 result
= TRASH_MoveFileToBucket(home_trash
, unix_path
);
545 HeapFree(GetProcessHeap(), 0, unix_path
);
549 static HRESULT
TRASH_GetDetails(const TRASH_BUCKET
*bucket
, LPCSTR filename
, WIN32_FIND_DATAW
*data
)
552 XDG_PARSED_FILE
*parsed
= NULL
;
553 char *original_file_name
= NULL
;
554 char *deletion_date
= NULL
;
557 HRESULT ret
= S_FALSE
;
558 LPWSTR original_dos_name
;
559 int suffix_length
= lstrlenA(trashinfo_suffix
);
560 int filename_length
= lstrlenA(filename
);
561 int files_length
= lstrlenA(bucket
->files_dir
);
562 int path_length
= max(lstrlenA(bucket
->info_dir
), files_length
);
564 path
= SHAlloc(path_length
+ filename_length
+ 1);
565 if (path
== NULL
) return E_OUTOFMEMORY
;
566 wsprintfA(path
, "%s%s", bucket
->files_dir
, filename
);
567 path
[path_length
+ filename_length
- suffix_length
] = 0; /* remove the '.trashinfo' */
568 if (lstat(path
, &stats
) == -1)
570 ERR("Error accessing data file for trashinfo %s (errno=%d)\n", filename
, errno
);
574 wsprintfA(path
, "%s%s", bucket
->info_dir
, filename
);
575 fd
= open(path
, O_RDONLY
);
578 ERR("Couldn't open trashinfo file %s (errno=%d)\n", path
, errno
);
582 parsed
= XDG_ParseDesktopFile(fd
);
585 ERR("Parse error in trashinfo file %s\n", path
);
589 original_file_name
= XDG_GetStringValue(parsed
, trashinfo_group
, "Path", XDG_URLENCODE
);
590 if (original_file_name
== NULL
)
592 ERR("No 'Path' entry in trashinfo file\n");
596 ZeroMemory(data
, sizeof(*data
));
597 data
->nFileSizeHigh
= (DWORD
)((LONGLONG
)stats
.st_size
>>32);
598 data
->nFileSizeLow
= stats
.st_size
& 0xffffffff;
599 RtlSecondsSince1970ToTime(stats
.st_mtime
, (LARGE_INTEGER
*)&data
->ftLastWriteTime
);
601 original_dos_name
= wine_get_dos_file_name(original_file_name
);
602 if (original_dos_name
!= NULL
)
604 lstrcpynW(data
->cFileName
, original_dos_name
, MAX_PATH
);
605 SHFree(original_dos_name
);
609 /* show only the file name */
610 char *file
= strrchr(original_file_name
, '/');
612 file
= original_file_name
;
613 MultiByteToWideChar(CP_UNIXCP
, 0, file
, -1, data
->cFileName
, MAX_PATH
);
616 deletion_date
= XDG_GetStringValue(parsed
, trashinfo_group
, "DeletionDate", 0);
622 sscanf(deletion_date
, "%d-%d-%dT%d:%d:%d",
623 &del_time
.tm_year
, &del_time
.tm_mon
, &del_time
.tm_mday
,
624 &del_time
.tm_hour
, &del_time
.tm_min
, &del_time
.tm_sec
);
625 del_time
.tm_year
-= 1900;
627 del_time
.tm_isdst
= -1;
628 del_secs
= mktime(&del_time
);
630 RtlSecondsSince1970ToTime(del_secs
, (LARGE_INTEGER
*)&data
->ftLastAccessTime
);
636 SHFree(original_file_name
);
637 SHFree(deletion_date
);
640 XDG_FreeParsedFile(parsed
);
644 static INT CALLBACK
free_item_callback(void *item
, void *lParam
)
650 static HDPA
enum_bucket_trashinfos(const TRASH_BUCKET
*bucket
, int *count
)
652 HDPA ret
= DPA_Create(32);
653 struct dirent
*entry
;
658 if (ret
== NULL
) goto failed
;
659 dir
= opendir(bucket
->info_dir
);
660 if (dir
== NULL
) goto failed
;
661 while ((entry
= readdir(dir
)) != NULL
)
664 int namelen
= lstrlenA(entry
->d_name
);
665 int suffixlen
= lstrlenA(trashinfo_suffix
);
666 if (namelen
<= suffixlen
||
667 lstrcmpA(entry
->d_name
+namelen
-suffixlen
, trashinfo_suffix
) != 0)
670 filename
= StrDupA(entry
->d_name
);
671 if (filename
== NULL
)
673 if (DPA_InsertPtr(ret
, DPA_APPEND
, filename
) == -1)
683 if (dir
) closedir(dir
);
685 DPA_DestroyCallback(ret
, free_item_callback
, NULL
);
689 HRESULT
TRASH_EnumItems(const WCHAR
*path
, LPITEMIDLIST
**pidls
, int *count
)
693 HRESULT err
= E_OUTOFMEMORY
;
697 FIXME("Ignoring path = %s\n", debugstr_w(path
));
699 if (!TRASH_EnsureInitialized()) return E_FAIL
;
700 tinfs
= enum_bucket_trashinfos(home_trash
, &ti_count
);
701 if (tinfs
== NULL
) return E_FAIL
;
702 *pidls
= SHAlloc(sizeof(LPITEMIDLIST
)*ti_count
);
703 if (!*pidls
) goto failed
;
704 for (i
=0; i
<ti_count
; i
++)
706 WIN32_FIND_DATAW data
;
709 filename
= DPA_GetPtr(tinfs
, i
);
710 if (FAILED(err
= TRASH_GetDetails(home_trash
, filename
, &data
)))
714 if (FAILED(err
= TRASH_CreateSimplePIDL(filename
, &data
, &(*pidls
)[pos
])))
719 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
725 for (j
=0; j
<pos
; j
++)
729 DPA_DestroyCallback(tinfs
, free_item_callback
, NULL
);
734 HRESULT
TRASH_RestoreItem(LPCITEMIDLIST pidl
){
735 int suffix_length
= strlen(trashinfo_suffix
);
736 LPCSHITEMID id
= &(pidl
->mkid
);
737 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
738 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
740 WIN32_FIND_DATAW data
;
743 TRACE("(%p)\n",pidl
);
744 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
746 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
749 TRASH_UnpackItemID(id
,&data
);
750 restore_path
= wine_get_unix_file_name(data
.cFileName
);
751 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
752 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
753 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
754 if(!rename(file_path
,restore_path
))
756 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
757 if(unlink(file_path
))
758 WARN("failed to delete the trashinfo file %s\n",filename
);
761 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
763 HeapFree(GetProcessHeap(), 0, restore_path
);
767 HRESULT
TRASH_EraseItem(LPCITEMIDLIST pidl
)
769 int suffix_length
= strlen(trashinfo_suffix
);
771 LPCSHITEMID id
= &(pidl
->mkid
);
772 const char *bucket_name
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
));
773 const char *filename
= (const char*)(id
->abID
+1+sizeof(WIN32_FIND_DATAW
)+strlen(bucket_name
)+1);
776 TRACE("(%p)\n",pidl
);
777 if(strcmp(filename
+strlen(filename
)-suffix_length
,trashinfo_suffix
))
779 ERR("pidl at %p is not a valid recycle bin entry\n",pidl
);
782 file_path
= SHAlloc(max(strlen(home_trash
->files_dir
),strlen(home_trash
->info_dir
))+strlen(filename
)+1);
783 sprintf(file_path
,"%s%s",home_trash
->info_dir
,filename
);
784 if(unlink(file_path
))
785 WARN("failed to delete the trashinfo file %s\n",filename
);
786 sprintf(file_path
,"%s%s",home_trash
->files_dir
,filename
);
787 file_path
[strlen(home_trash
->files_dir
)+strlen(filename
)-suffix_length
] = '\0';
788 if(unlink(file_path
))
789 WARN("could not erase %s from the trash (errno=%i)\n",filename
,errno
);
794 #endif /* HAVE_CORESERVICES_CORESERVICES_H */