* Neither ours nor BeOS' find_directory() will return an error if the directory

does not exist yet.
* Therefore, only BDirectory::SetTo() will fail if the trash does not exist
  yet. Changed the code to actually work as expected, now.
* Fixed old and new style violations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36524 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-04-29 07:37:06 +00:00
parent d62afe7ab0
commit 0230fc14ea
+34 -37
View File
@@ -2362,13 +2362,19 @@ FSGetTrashDir(BDirectory *trashDir, dev_t dev)
return result; return result;
BPath path; BPath path;
bool created = false;
result = find_directory(B_TRASH_DIRECTORY, &path, false, &volume); result = find_directory(B_TRASH_DIRECTORY, &path, false, &volume);
if (result != B_OK) { if (result != B_OK)
result = find_directory(B_TRASH_DIRECTORY, &path, true, return result;
&volume);
created = true; result = trashDir->SetTo(path.Path());
if (result == B_OK) {
// Directory already exists, we're done
return B_OK;
} }
// The trash directory does not exist yet - change that!
result = create_directory(path.Path(), 0755);
if (result != B_OK) if (result != B_OK)
return result; return result;
@@ -2376,40 +2382,31 @@ FSGetTrashDir(BDirectory *trashDir, dev_t dev)
if (result != B_OK) if (result != B_OK)
return result; return result;
if (created) // make trash invisible
{ StatStruct sbuf;
// make trash invisible trashDir->GetStat(&sbuf);
StatStruct sbuf;
trashDir->GetStat(&sbuf);
PoseInfo poseInfo; PoseInfo poseInfo;
poseInfo.fInvisible = true; poseInfo.fInvisible = true;
poseInfo.fInitedDirectory = sbuf.st_ino; poseInfo.fInitedDirectory = sbuf.st_ino;
trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo, trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo,
sizeof(PoseInfo)); sizeof(PoseInfo));
size_t size; // set trash icon
const void* data = GetTrackerResources()-> size_t size;
LoadResource('ICON', R_TrashIcon, &size); const void* data
if (data != NULL) { = GetTrackerResources()->LoadResource('ICON', R_TrashIcon, &size);
trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, if (data != NULL)
data, size); trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size);
}
data = GetTrackerResources()-> data = GetTrackerResources()->LoadResource('MICN', R_TrashIcon, &size);
LoadResource('MICN', R_TrashIcon, &size); if (data != NULL)
if (data != NULL) { trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size);
trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0,
data, size); data = GetTrackerResources()->LoadResource(B_VECTOR_ICON_TYPE, R_TrashIcon,
} &size);
#ifdef __HAIKU__ if (data != NULL)
data = GetTrackerResources()-> trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, data, size);
LoadResource(B_VECTOR_ICON_TYPE, R_TrashIcon, &size);
if (data != NULL) {
trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0,
data, size);
}
#endif
}
return B_OK; return B_OK;
} }