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
+59 -72
View File
@@ -1024,7 +1024,7 @@ MoveTask(BObjectList<entry_ref>* srcList, BEntry* destEntry, BList* pointList,
// resolve name collisions and hierarchy problems // resolve name collisions and hierarchy problems
if (CheckName(moveMode, &sourceEntry, &destDir, if (CheckName(moveMode, &sourceEntry, &destDir,
collisionCount > 1, conflictCheckResult) != B_OK) { collisionCount > 1, conflictCheckResult) != B_OK) {
// we will skip the current item, because we got a conflict // we will skip the current item, because we got a conflict
// and were asked to or because there was some conflict // and were asked to or because there was some conflict
@@ -1152,7 +1152,7 @@ CopyFile(BEntry* srcFile, StatStruct* srcStat, BDirectory* destDir,
BEntry conflictingEntry; BEntry conflictingEntry;
if (destDir->FindEntry(destName, &conflictingEntry) == B_OK) { if (destDir->FindEntry(destName, &conflictingEntry) == B_OK) {
switch (loopControl->OverwriteOnConflict(srcFile, destName, destDir, switch (loopControl->OverwriteOnConflict(srcFile, destName, destDir,
false, false)) { false, false)) {
case TrackerCopyLoopControl::kSkip: case TrackerCopyLoopControl::kSkip:
// we are about to ignore this entire directory // we are about to ignore this entire directory
return; return;
@@ -1573,36 +1573,35 @@ status_t
RecursiveMove(BEntry* entry, BDirectory* destDir, RecursiveMove(BEntry* entry, BDirectory* destDir,
CopyLoopControl* loopControl) CopyLoopControl* loopControl)
{ {
char name[B_FILE_NAME_LENGTH]; const char* name = entry->Name();
if (entry->GetName(name) == B_OK) {
if (destDir->Contains(name)) { if (destDir->Contains(name)) {
BPath path (destDir, name); BPath path (destDir, name);
BDirectory subDir (path.Path()); BDirectory subDir (path.Path());
entry_ref ref; entry_ref ref;
entry->GetRef(&ref); entry->GetRef(&ref);
BDirectory source(&ref); BDirectory source(&ref);
if (source.InitCheck() == B_OK) { if (source.InitCheck() == B_OK) {
source.Rewind(); source.Rewind();
BEntry current; BEntry current;
while (source.GetNextEntry(&current) == B_OK) { while (source.GetNextEntry(&current) == B_OK) {
if (current.IsDirectory()) { if (current.IsDirectory()) {
RecursiveMove(&current, &subDir, loopControl); RecursiveMove(&current, &subDir, loopControl);
current.Remove(); current.Remove();
} else { } else {
current.GetName(name); name = current.Name();
if (loopControl->OverwriteOnConflict(&current, name, if (loopControl->OverwriteOnConflict(&current, name,
&subDir, true, false) &subDir, true, false)
!= TrackerCopyLoopControl::kSkip) { != TrackerCopyLoopControl::kSkip) {
MoveError::FailOnError(current.MoveTo(&subDir, MoveError::FailOnError(current.MoveTo(&subDir,
NULL, true)); NULL, true));
}
} }
} }
} }
entry->Remove(); }
} else entry->Remove();
MoveError::FailOnError(entry->MoveTo(destDir)); } else
} MoveError::FailOnError(entry->MoveTo(destDir));
return B_OK; return B_OK;
} }
@@ -1998,7 +1997,6 @@ ConflictCheckResult
PreFlightNameCheck(BObjectList<entry_ref>* srcList, const BDirectory* destDir, PreFlightNameCheck(BObjectList<entry_ref>* srcList, const BDirectory* destDir,
int32* collisionCount, uint32 moveMode) int32* collisionCount, uint32 moveMode)
{ {
// count the number of name collisions in dest folder // count the number of name collisions in dest folder
*collisionCount = 0; *collisionCount = 0;
@@ -2009,10 +2007,8 @@ PreFlightNameCheck(BObjectList<entry_ref>* srcList, const BDirectory* destDir,
BDirectory parent; BDirectory parent;
entry.GetParent(&parent); entry.GetParent(&parent);
if (parent != *destDir) { if (parent != *destDir && destDir->Contains(srcRef->name))
if (destDir->Contains(srcRef->name)) (*collisionCount)++;
(*collisionCount)++;
}
} }
// prompt user only if there is more than one collision, otherwise the // prompt user only if there is more than one collision, otherwise the
@@ -2064,16 +2060,15 @@ FileStatToString(StatStruct* stat, char* buffer, int32 length)
status_t status_t
CheckName(uint32 moveMode, const BEntry* sourceEntry, CheckName(uint32 moveMode, const BEntry* sourceEntry,
const BDirectory* destDir, bool multipleCollisions, const BDirectory* destDir, bool multipleCollisions,
ConflictCheckResult &replaceAll) ConflictCheckResult& conflictMode)
{ {
if (moveMode == kDuplicateSelection) if (moveMode == kDuplicateSelection) {
// when duplicating, we will never have a conflict // when duplicating, we will never have a conflict
return B_OK; return B_OK;
}
// see if item already exists in destination dir // see if item already exists in destination dir
status_t err = B_OK; const char* name = sourceEntry->Name();
char name[B_FILE_NAME_LENGTH];
sourceEntry->GetName(name);
bool sourceIsDirectory = sourceEntry->IsDirectory(); bool sourceIsDirectory = sourceEntry->IsDirectory();
BDirectory srcDirectory; BDirectory srcDirectory;
@@ -2082,8 +2077,7 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
BEntry destEntry; BEntry destEntry;
destDir->GetEntry(&destEntry); destDir->GetEntry(&destEntry);
if (moveMode != kCreateLink if (moveMode != kCreateLink && moveMode != kCreateRelativeLink
&& moveMode != kCreateRelativeLink
&& (srcDirectory == *destDir && (srcDirectory == *destDir
|| srcDirectory.Contains(&destEntry))) { || srcDirectory.Contains(&destEntry))) {
BAlert* alert = new BAlert("", BAlert* alert = new BAlert("",
@@ -2108,9 +2102,10 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
} }
BEntry entry; BEntry entry;
if (destDir->FindEntry(name, &entry) != B_OK) if (destDir->FindEntry(name, &entry) != B_OK) {
// no conflict, return // no conflict, return
return B_OK; return B_OK;
}
if (moveMode == kCreateLink || moveMode == kCreateRelativeLink) { if (moveMode == kCreateLink || moveMode == kCreateRelativeLink) {
// if we are creating link in the same directory, the conflict will // 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(); bool destIsDir = entry.IsDirectory();
// be sure not to replace the parent directory of the item being moved // be sure not to replace the parent directory of the item being moved
if (destIsDir) { if (destIsDir) {
BDirectory test_dir(&entry); BDirectory targetDir(&entry);
if (test_dir.Contains(sourceEntry)) { if (targetDir.Contains(sourceEntry)) {
BAlert* alert = new BAlert("", BAlert* alert = new BAlert("",
B_TRANSLATE("You can't replace a folder " B_TRANSLATE("You can't replace a folder "
"with one of its sub-folders."), "with one of its sub-folders."),
@@ -2141,18 +2136,18 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
if (moveMode != kCreateLink if (moveMode != kCreateLink
&& moveMode != kCreateRelativeLink && moveMode != kCreateRelativeLink
&& destIsDir != sourceIsDirectory) { && destIsDir != sourceIsDirectory) {
BAlert* alert = new BAlert("", sourceIsDirectory BAlert* alert = new BAlert("", sourceIsDirectory
? B_TRANSLATE("You cannot replace a file with a folder or a " ? B_TRANSLATE("You cannot replace a file with a folder or a "
"symbolic link.") "symbolic link.")
: B_TRANSLATE("You cannot replace a folder or a symbolic link " : B_TRANSLATE("You cannot replace a folder or a symbolic link "
"with a file."), B_TRANSLATE("OK"), 0, 0, B_WIDTH_AS_USUAL, "with a file."), B_TRANSLATE("OK"), 0, 0, B_WIDTH_AS_USUAL,
B_WARNING_ALERT); B_WARNING_ALERT);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(); alert->Go();
return B_ERROR; return B_ERROR;
} }
if (replaceAll != kReplaceAll) { if (conflictMode != kReplaceAll) {
// prompt user to determine whether to replace or not // prompt user to determine whether to replace or not
BString replaceMsg; BString replaceMsg;
@@ -2170,8 +2165,8 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
char sourceBuffer[96], destBuffer[96]; char sourceBuffer[96], destBuffer[96];
StatStruct statBuffer; StatStruct statBuffer;
if (!sourceEntry->IsDirectory() && sourceEntry->GetStat( if (!sourceEntry->IsDirectory()
&statBuffer) == B_OK) { && sourceEntry->GetStat(&statBuffer) == B_OK) {
FileStatToString(&statBuffer, sourceBuffer, 96); FileStatToString(&statBuffer, sourceBuffer, 96);
} else } else
sourceBuffer[0] = '\0'; sourceBuffer[0] = '\0';
@@ -2185,10 +2180,8 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
replaceMsg.ReplaceAll("%name", name); replaceMsg.ReplaceAll("%name", name);
replaceMsg.ReplaceFirst("%dest", destBuffer); replaceMsg.ReplaceFirst("%dest", destBuffer);
replaceMsg.ReplaceFirst("%src", sourceBuffer); replaceMsg.ReplaceFirst("%src", sourceBuffer);
replaceMsg.ReplaceFirst("%movemode", replaceMsg.ReplaceFirst("%movemode", moveMode == kMoveSelectionTo
moveMode == kMoveSelectionTo ? B_TRANSLATE("moving") : B_TRANSLATE("copying"));
? B_TRANSLATE("moving")
: B_TRANSLATE("copying"));
} }
// special case single collision (don't need Replace All shortcut) // special case single collision (don't need Replace All shortcut)
@@ -2216,22 +2209,21 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
} }
// delete destination item // delete destination item
if (!destIsDir) if (destIsDir)
err = entry.Remove();
else
return B_OK; 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 " BString error(B_TRANSLATE("There was a problem trying to replace "
"\"%name\". The item might be open or busy.")); "\"%name\". The item might be open or busy."));
error.ReplaceFirst("%name", name);; error.ReplaceFirst("%name", name);
BAlert* alert = new BAlert("", error.String(), BAlert* alert = new BAlert("", error.String(),
B_TRANSLATE("Cancel"), 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT); B_TRANSLATE("Cancel"), 0, 0, 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();
} }
return err; return status;
} }
@@ -2962,14 +2954,10 @@ FSRecursiveCreateFolder(BPath path)
entry.SetTo(path.Path()); entry.SetTo(path.Path());
if (entry.Exists()) if (entry.Exists())
return B_FILE_EXISTS; return B_FILE_EXISTS;
else {
char name[B_FILE_NAME_LENGTH];
BDirectory parent;
entry.GetParent(&parent); BDirectory parent;
entry.GetName(name); entry.GetParent(&parent);
parent.CreateDirectory(name, NULL); parent.CreateDirectory(entry.Name(), NULL);
}
return B_OK; return B_OK;
} }
@@ -3017,8 +3005,7 @@ _RestoreTask(BObjectList<entry_ref>* list)
if (!originalEntry.Exists()) { if (!originalEntry.Exists()) {
BDirectory dir(parentPath.Path()); BDirectory dir(parentPath.Path());
if (dir.InitCheck() == B_OK) { if (dir.InitCheck() == B_OK) {
char leafName[B_FILE_NAME_LENGTH]; const char* leafName = originalEntry.Name();
originalEntry.GetName(leafName);
if (entry.MoveTo(&dir, leafName) == B_OK) { if (entry.MoveTo(&dir, leafName) == B_OK) {
BNode node(&entry); BNode node(&entry);
if (node.InitCheck() == B_OK) if (node.InitCheck() == B_OK)