libtracker: delete folder cleanup.
* Removed a number of superfluous BDirectory::Rewind() calls. * Renamed some variables.
This commit is contained in:
@@ -2237,58 +2237,54 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
FSDeleteFolder(BEntry* dir_entry, CopyLoopControl* loopControl,
|
FSDeleteFolder(BEntry* dirEntry, CopyLoopControl* loopControl,
|
||||||
bool update_status, bool delete_top_dir, bool upateFileNameInStatus)
|
bool updateStatus, bool deleteTopDir, bool upateFileNameInStatus)
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
BDirectory dir(dirEntry);
|
||||||
BEntry entry;
|
|
||||||
BDirectory dir;
|
|
||||||
status_t err;
|
|
||||||
|
|
||||||
dir.SetTo(dir_entry);
|
|
||||||
dir.Rewind();
|
|
||||||
// loop through everything in folder and delete it, skipping trouble files
|
// loop through everything in folder and delete it, skipping trouble files
|
||||||
for (;;) {
|
BEntry entry;
|
||||||
if (dir.GetNextEntry(&entry) != B_OK)
|
while (dir.GetNextEntry(&entry) == B_OK) {
|
||||||
break;
|
entry_ref ref;
|
||||||
|
|
||||||
entry.GetRef(&ref);
|
entry.GetRef(&ref);
|
||||||
|
|
||||||
if (loopControl->CheckUserCanceled())
|
if (loopControl->CheckUserCanceled())
|
||||||
return kTrashCanceled;
|
return kTrashCanceled;
|
||||||
|
|
||||||
|
status_t status;
|
||||||
|
|
||||||
if (entry.IsDirectory())
|
if (entry.IsDirectory())
|
||||||
err = FSDeleteFolder(&entry, loopControl, update_status, true,
|
status = FSDeleteFolder(&entry, loopControl, updateStatus, true,
|
||||||
upateFileNameInStatus);
|
upateFileNameInStatus);
|
||||||
else {
|
else {
|
||||||
err = entry.Remove();
|
status = entry.Remove();
|
||||||
if (update_status) {
|
if (updateStatus) {
|
||||||
loopControl->UpdateStatus(upateFileNameInStatus ? ref.name
|
loopControl->UpdateStatus(upateFileNameInStatus ? ref.name
|
||||||
: "", ref, 1, true);
|
: "", ref, 1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == kTrashCanceled)
|
if (status == kTrashCanceled)
|
||||||
return kTrashCanceled;
|
return kTrashCanceled;
|
||||||
else if (err == B_OK)
|
|
||||||
dir.Rewind();
|
if (status != B_OK) {
|
||||||
else {
|
|
||||||
loopControl->FileError(B_TRANSLATE_NOCOLLECT(
|
loopControl->FileError(B_TRANSLATE_NOCOLLECT(
|
||||||
kFileDeleteErrorString), ref.name, err, false);
|
kFileDeleteErrorString), ref.name, status, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loopControl->CheckUserCanceled())
|
if (loopControl->CheckUserCanceled())
|
||||||
return kTrashCanceled;
|
return kTrashCanceled;
|
||||||
|
|
||||||
dir_entry->GetRef(&ref);
|
entry_ref ref;
|
||||||
|
dirEntry->GetRef(&ref);
|
||||||
|
|
||||||
if (update_status && delete_top_dir)
|
if (updateStatus && deleteTopDir)
|
||||||
loopControl->UpdateStatus(NULL, ref, 1);
|
loopControl->UpdateStatus(NULL, ref, 1);
|
||||||
|
|
||||||
if (delete_top_dir)
|
if (deleteTopDir)
|
||||||
return dir_entry->Remove();
|
return dirEntry->Remove();
|
||||||
else
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2810,7 +2806,7 @@ status_t
|
|||||||
empty_trash(void*)
|
empty_trash(void*)
|
||||||
{
|
{
|
||||||
// empty trash on all mounted volumes
|
// empty trash on all mounted volumes
|
||||||
status_t err = B_OK;
|
status_t status = B_OK;
|
||||||
|
|
||||||
TrackerCopyLoopControl loopControl(kTrashState);
|
TrackerCopyLoopControl loopControl(kTrashState);
|
||||||
|
|
||||||
@@ -2835,9 +2831,9 @@ empty_trash(void*)
|
|||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
entry.GetRef(&ref);
|
entry.GetRef(&ref);
|
||||||
srcList.AddItem(&ref);
|
srcList.AddItem(&ref);
|
||||||
err = CalcItemsAndSize(&loopControl, &srcList, volume.BlockSize(),
|
status = CalcItemsAndSize(&loopControl, &srcList, volume.BlockSize(),
|
||||||
&totalCount, &totalSize);
|
&totalCount, &totalSize);
|
||||||
if (err != B_OK)
|
if (status != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
srcList.MakeEmpty();
|
srcList.MakeEmpty();
|
||||||
@@ -2846,7 +2842,7 @@ empty_trash(void*)
|
|||||||
totalCount--;
|
totalCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == B_OK) {
|
if (status == B_OK) {
|
||||||
loopControl.Init(totalCount, totalCount);
|
loopControl.Init(totalCount, totalCount);
|
||||||
|
|
||||||
volumeRoster.Rewind();
|
volumeRoster.Rewind();
|
||||||
@@ -2860,11 +2856,11 @@ empty_trash(void*)
|
|||||||
|
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
trashDirectory.GetEntry(&entry);
|
trashDirectory.GetEntry(&entry);
|
||||||
err = FSDeleteFolder(&entry, &loopControl, true, false);
|
status = FSDeleteFolder(&entry, &loopControl, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != B_OK && err != kTrashCanceled && err != kUserCanceled) {
|
if (status != B_OK && status != kTrashCanceled && status != kUserCanceled) {
|
||||||
BAlert* alert = new BAlert("", B_TRANSLATE("Error emptying Trash"),
|
BAlert* alert = new BAlert("", B_TRANSLATE("Error emptying Trash"),
|
||||||
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
@@ -2922,9 +2918,9 @@ _DeleteTask(BObjectList<entry_ref>* list, bool confirm)
|
|||||||
int32 totalItems = 0;
|
int32 totalItems = 0;
|
||||||
int64 totalSize = 0;
|
int64 totalSize = 0;
|
||||||
|
|
||||||
status_t err = CalcItemsAndSize(&loopControl, list, 0, &totalItems,
|
status_t status = CalcItemsAndSize(&loopControl, list, 0, &totalItems,
|
||||||
&totalSize);
|
&totalSize);
|
||||||
if (err == B_OK) {
|
if (status == B_OK) {
|
||||||
loopControl.Init(totalItems, totalItems);
|
loopControl.Init(totalItems, totalItems);
|
||||||
|
|
||||||
int32 count = list->CountItems();
|
int32 count = list->CountItems();
|
||||||
@@ -2933,14 +2929,16 @@ _DeleteTask(BObjectList<entry_ref>* list, bool confirm)
|
|||||||
BEntry entry(&ref);
|
BEntry entry(&ref);
|
||||||
loopControl.UpdateStatus(ref.name, ref, 1, true);
|
loopControl.UpdateStatus(ref.name, ref, 1, true);
|
||||||
if (entry.IsDirectory())
|
if (entry.IsDirectory())
|
||||||
err = FSDeleteFolder(&entry, &loopControl, true, true, true);
|
status = FSDeleteFolder(&entry, &loopControl, true, true, true);
|
||||||
else
|
else
|
||||||
err = entry.Remove();
|
status = entry.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != kTrashCanceled && err != kUserCanceled && err != B_OK) {
|
if (status != kTrashCanceled && status != kUserCanceled
|
||||||
|
&& status != B_OK) {
|
||||||
BAlert* alert = new BAlert("", B_TRANSLATE("Error deleting items"),
|
BAlert* alert = new BAlert("", B_TRANSLATE("Error deleting items"),
|
||||||
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL,
|
||||||
|
B_WARNING_ALERT);
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user