Tracker: Write Trash icon attrs only once

Also create Trash if does not exist but check the if the icon
attrs are set separately.

Only set the vector trash icon #ifdef __HAIKU__ does this
even matter anymore?
This commit is contained in:
John Scipione
2014-07-17 14:51:26 -04:00
parent 7f68dcb4a7
commit 537e1fff3e
+40 -35
View File
@@ -2498,46 +2498,51 @@ FSGetTrashDir(BDirectory* trashDir, dev_t dev)
return result; return result;
result = trashDir->SetTo(path.Path()); result = trashDir->SetTo(path.Path());
if (result == B_OK) { if (result != B_OK) {
// Directory already exists, we're done // Trash directory does not exist yet, create it.
return B_OK; result = create_directory(path.Path(), 0755);
if (result != B_OK)
return result;
result = trashDir->SetTo(path.Path());
if (result != B_OK)
return result;
// make Trash directory invisible
StatStruct sbuf;
trashDir->GetStat(&sbuf);
PoseInfo poseInfo;
poseInfo.fInvisible = true;
poseInfo.fInitedDirectory = sbuf.st_ino;
trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo,
sizeof(PoseInfo));
} }
// The trash directory does not exist yet - change that! // set Trash icons (if they haven't already been set)
attr_info attrInfo;
result = create_directory(path.Path(), 0755);
if (result != B_OK)
return result;
result = trashDir->SetTo(path.Path());
if (result != B_OK)
return result;
// make trash invisible
StatStruct sbuf;
trashDir->GetStat(&sbuf);
PoseInfo poseInfo;
poseInfo.fInvisible = true;
poseInfo.fInitedDirectory = sbuf.st_ino;
trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo,
sizeof(PoseInfo));
// set trash icon
size_t size; size_t size;
const void* data const void* data;
= GetTrackerResources()->LoadResource('ICON', R_TrashIcon, &size); if (trashDir->GetAttrInfo(kAttrLargeIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
if (data != NULL) data = GetTrackerResources()->LoadResource('ICON', R_TrashIcon, &size);
trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size); if (data != NULL)
trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size);
}
data = GetTrackerResources()->LoadResource('MICN', R_TrashIcon, &size); if (trashDir->GetAttrInfo(kAttrMiniIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
if (data != NULL) data = GetTrackerResources()->LoadResource('MICN', R_TrashIcon, &size);
trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size); if (data != NULL)
trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size);
}
data = GetTrackerResources()->LoadResource(B_VECTOR_ICON_TYPE, #ifdef __HAIKU__
R_TrashIcon, &size); if (trashDir->GetAttrInfo(kAttrIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
if (data != NULL) data = GetTrackerResources()->LoadResource(B_VECTOR_ICON_TYPE,
trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, data, size); R_TrashIcon, &size);
if (data != NULL)
trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, data, size);
}
#endif // __HAIKU__
return B_OK; return B_OK;
} }