Tracker: Use BEntry::Name(), minor cleanup.

* Use BEntry::Name() over GetName() where appropriate.
* Fixed some weird indentation.
* Simplified some constructs.
This commit is contained in:
Axel Dörfler
2015-08-17 21:09:46 +02:00
parent 103adddb37
commit 0104e6facb
+26 -39
View File
@@ -1573,8 +1573,8 @@ status_t
RecursiveMove(BEntry* entry, BDirectory* destDir,
CopyLoopControl* loopControl)
{
char name[B_FILE_NAME_LENGTH];
if (entry->GetName(name) == B_OK) {
const char* name = entry->Name();
if (destDir->Contains(name)) {
BPath path (destDir, name);
BDirectory subDir (path.Path());
@@ -1589,7 +1589,7 @@ RecursiveMove(BEntry* entry, BDirectory* destDir,
RecursiveMove(&current, &subDir, loopControl);
current.Remove();
} else {
current.GetName(name);
name = current.Name();
if (loopControl->OverwriteOnConflict(&current, name,
&subDir, true, false)
!= TrackerCopyLoopControl::kSkip) {
@@ -1602,7 +1602,6 @@ RecursiveMove(BEntry* entry, BDirectory* destDir,
entry->Remove();
} else
MoveError::FailOnError(entry->MoveTo(destDir));
}
return B_OK;
}
@@ -1998,7 +1997,6 @@ ConflictCheckResult
PreFlightNameCheck(BObjectList<entry_ref>* srcList, const BDirectory* destDir,
int32* collisionCount, uint32 moveMode)
{
// count the number of name collisions in dest folder
*collisionCount = 0;
@@ -2009,11 +2007,9 @@ PreFlightNameCheck(BObjectList<entry_ref>* srcList, const BDirectory* destDir,
BDirectory parent;
entry.GetParent(&parent);
if (parent != *destDir) {
if (destDir->Contains(srcRef->name))
if (parent != *destDir && destDir->Contains(srcRef->name))
(*collisionCount)++;
}
}
// prompt user only if there is more than one collision, otherwise the
// single collision case will be handled as a "Prompt" case by CheckName
@@ -2064,16 +2060,15 @@ FileStatToString(StatStruct* stat, char* buffer, int32 length)
status_t
CheckName(uint32 moveMode, const BEntry* sourceEntry,
const BDirectory* destDir, bool multipleCollisions,
ConflictCheckResult &replaceAll)
ConflictCheckResult& conflictMode)
{
if (moveMode == kDuplicateSelection)
if (moveMode == kDuplicateSelection) {
// when duplicating, we will never have a conflict
return B_OK;
}
// see if item already exists in destination dir
status_t err = B_OK;
char name[B_FILE_NAME_LENGTH];
sourceEntry->GetName(name);
const char* name = sourceEntry->Name();
bool sourceIsDirectory = sourceEntry->IsDirectory();
BDirectory srcDirectory;
@@ -2082,8 +2077,7 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
BEntry destEntry;
destDir->GetEntry(&destEntry);
if (moveMode != kCreateLink
&& moveMode != kCreateRelativeLink
if (moveMode != kCreateLink && moveMode != kCreateRelativeLink
&& (srcDirectory == *destDir
|| srcDirectory.Contains(&destEntry))) {
BAlert* alert = new BAlert("",
@@ -2108,9 +2102,10 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
}
BEntry entry;
if (destDir->FindEntry(name, &entry) != B_OK)
if (destDir->FindEntry(name, &entry) != B_OK) {
// no conflict, return
return B_OK;
}
if (moveMode == kCreateLink || moveMode == kCreateRelativeLink) {
// if we are creating link in the same directory, the conflict will
@@ -2124,8 +2119,8 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
bool destIsDir = entry.IsDirectory();
// be sure not to replace the parent directory of the item being moved
if (destIsDir) {
BDirectory test_dir(&entry);
if (test_dir.Contains(sourceEntry)) {
BDirectory targetDir(&entry);
if (targetDir.Contains(sourceEntry)) {
BAlert* alert = new BAlert("",
B_TRANSLATE("You can't replace a folder "
"with one of its sub-folders."),
@@ -2152,7 +2147,7 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
return B_ERROR;
}
if (replaceAll != kReplaceAll) {
if (conflictMode != kReplaceAll) {
// prompt user to determine whether to replace or not
BString replaceMsg;
@@ -2170,8 +2165,8 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
char sourceBuffer[96], destBuffer[96];
StatStruct statBuffer;
if (!sourceEntry->IsDirectory() && sourceEntry->GetStat(
&statBuffer) == B_OK) {
if (!sourceEntry->IsDirectory()
&& sourceEntry->GetStat(&statBuffer) == B_OK) {
FileStatToString(&statBuffer, sourceBuffer, 96);
} else
sourceBuffer[0] = '\0';
@@ -2185,10 +2180,8 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
replaceMsg.ReplaceAll("%name", name);
replaceMsg.ReplaceFirst("%dest", destBuffer);
replaceMsg.ReplaceFirst("%src", sourceBuffer);
replaceMsg.ReplaceFirst("%movemode",
moveMode == kMoveSelectionTo
? B_TRANSLATE("moving")
: B_TRANSLATE("copying"));
replaceMsg.ReplaceFirst("%movemode", moveMode == kMoveSelectionTo
? B_TRANSLATE("moving") : B_TRANSLATE("copying"));
}
// special case single collision (don't need Replace All shortcut)
@@ -2216,22 +2209,21 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
}
// delete destination item
if (!destIsDir)
err = entry.Remove();
else
if (destIsDir)
return B_OK;
if (err != B_OK) {
status_t status = entry.Remove();
if (status != B_OK) {
BString error(B_TRANSLATE("There was a problem trying to replace "
"\"%name\". The item might be open or busy."));
error.ReplaceFirst("%name", name);;
error.ReplaceFirst("%name", name);
BAlert* alert = new BAlert("", error.String(),
B_TRANSLATE("Cancel"), 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
}
return err;
return status;
}
@@ -2962,14 +2954,10 @@ FSRecursiveCreateFolder(BPath path)
entry.SetTo(path.Path());
if (entry.Exists())
return B_FILE_EXISTS;
else {
char name[B_FILE_NAME_LENGTH];
BDirectory parent;
BDirectory parent;
entry.GetParent(&parent);
entry.GetName(name);
parent.CreateDirectory(name, NULL);
}
parent.CreateDirectory(entry.Name(), NULL);
return B_OK;
}
@@ -3017,8 +3005,7 @@ _RestoreTask(BObjectList<entry_ref>* list)
if (!originalEntry.Exists()) {
BDirectory dir(parentPath.Path());
if (dir.InitCheck() == B_OK) {
char leafName[B_FILE_NAME_LENGTH];
originalEntry.GetName(leafName);
const char* leafName = originalEntry.Name();
if (entry.MoveTo(&dir, leafName) == B_OK) {
BNode node(&entry);
if (node.InitCheck() == B_OK)