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:
@@ -1573,8 +1573,8 @@ 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());
|
||||||
@@ -1589,7 +1589,7 @@ RecursiveMove(BEntry* entry, BDirectory* destDir,
|
|||||||
RecursiveMove(¤t, &subDir, loopControl);
|
RecursiveMove(¤t, &subDir, loopControl);
|
||||||
current.Remove();
|
current.Remove();
|
||||||
} else {
|
} else {
|
||||||
current.GetName(name);
|
name = current.Name();
|
||||||
if (loopControl->OverwriteOnConflict(¤t, name,
|
if (loopControl->OverwriteOnConflict(¤t, name,
|
||||||
&subDir, true, false)
|
&subDir, true, false)
|
||||||
!= TrackerCopyLoopControl::kSkip) {
|
!= TrackerCopyLoopControl::kSkip) {
|
||||||
@@ -1602,7 +1602,6 @@ RecursiveMove(BEntry* entry, BDirectory* destDir,
|
|||||||
entry->Remove();
|
entry->Remove();
|
||||||
} else
|
} else
|
||||||
MoveError::FailOnError(entry->MoveTo(destDir));
|
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,11 +2007,9 @@ 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
|
||||||
// single collision case will be handled as a "Prompt" case by CheckName
|
// 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
|
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."),
|
||||||
@@ -2152,7 +2147,7 @@ CheckName(uint32 moveMode, const BEntry* sourceEntry,
|
|||||||
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;
|
|
||||||
|
|
||||||
|
BDirectory parent;
|
||||||
entry.GetParent(&parent);
|
entry.GetParent(&parent);
|
||||||
entry.GetName(name);
|
parent.CreateDirectory(entry.Name(), NULL);
|
||||||
parent.CreateDirectory(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)
|
||||||
|
|||||||
Reference in New Issue
Block a user