Tracker: style fixes to FSUtils

This commit is contained in:
John Scipione
2014-06-20 21:01:50 -04:00
parent 086eaa586b
commit aee40335a9
2 changed files with 47 additions and 31 deletions
+46 -30
View File
@@ -500,8 +500,9 @@ FSGetPoseLocation(const BNode* node, BPoint* point)
PoseInfo poseInfo; PoseInfo poseInfo;
if (ReadAttr(node, kAttrPoseInfo, kAttrPoseInfoForeign, if (ReadAttr(node, kAttrPoseInfo, kAttrPoseInfoForeign,
B_RAW_TYPE, 0, &poseInfo, sizeof(poseInfo), &PoseInfo::EndianSwap) B_RAW_TYPE, 0, &poseInfo, sizeof(poseInfo), &PoseInfo::EndianSwap)
== kReadAttrFailed) == kReadAttrFailed) {
return false; return false;
}
if (poseInfo.fInitedDirectory == -1LL) if (poseInfo.fInitedDirectory == -1LL)
return false; return false;
@@ -517,16 +518,17 @@ SetUpPoseLocation(ino_t sourceParentIno, ino_t destParentIno,
const BNode* sourceNode, BNode* destNode, BPoint* loc) const BNode* sourceNode, BNode* destNode, BPoint* loc)
{ {
BPoint point; BPoint point;
if (!loc if (loc == NULL
// we don't have a position yet // we don't have a position yet
&& sourceParentIno != destParentIno && sourceParentIno != destParentIno
// we aren't copying into the same directory // we aren't copying into the same directory
&& FSGetPoseLocation(sourceNode, &point)) && FSGetPoseLocation(sourceNode, &point)) {
// the original has a valid inited location // the original has a valid inited location
loc = &point; loc = &point;
// copy the originals location // copy the originals location
}
if (loc && loc != (BPoint*)-1) { if (loc != NULL && loc != (BPoint*)-1) {
// loc of -1 is used when copying/moving into a window in list mode // loc of -1 is used when copying/moving into a window in list mode
// where copying positions would not work // where copying positions would not work
// ToSo: // ToSo:
@@ -656,7 +658,6 @@ ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
"Shift key and click \"%toConfirmAction\".")); "Shift key and click \"%toConfirmAction\"."));
} else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY) } else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY)
|| DirectoryMatchesOrContains(entry, B_SYSTEM_SETTINGS_DIRECTORY)) { || DirectoryMatchesOrContains(entry, B_SYSTEM_SETTINGS_DIRECTORY)) {
if (DirectoryMatchesOrContains(entry, "beos_mime", if (DirectoryMatchesOrContains(entry, "beos_mime",
B_USER_SETTINGS_DIRECTORY) B_USER_SETTINGS_DIRECTORY)
|| DirectoryMatchesOrContains(entry, "beos_mime", || DirectoryMatchesOrContains(entry, "beos_mime",
@@ -839,6 +840,7 @@ InitCopy(CopyLoopControl* loopControl, uint32 moveMode,
} }
break; break;
} }
return B_OK; return B_OK;
} }
@@ -980,8 +982,9 @@ MoveTask(BObjectList<entry_ref>* srcList, BEntry* destEntry, BList* pointList,
&& moveMode != kDuplicateSelection && moveMode != kDuplicateSelection
&& !destIsTrash && !destIsTrash
&& (srcRef->device == destRef.device && (srcRef->device == destRef.device
&& srcRef->directory == deststat.st_ino)) && srcRef->directory == deststat.st_ino)) {
continue; continue;
}
if (loopControl.CheckUserCanceled()) if (loopControl.CheckUserCanceled())
break; break;
@@ -1000,7 +1003,7 @@ MoveTask(BObjectList<entry_ref>* srcList, BEntry* destEntry, BList* pointList,
// are we moving item to trash? // are we moving item to trash?
if (destIsTrash) { if (destIsTrash) {
if (pointList) if (pointList != NULL)
loc = (BPoint*)pointList->ItemAt(i); loc = (BPoint*)pointList->ItemAt(i);
result = MoveEntryToTrash(&sourceEntry, loc, undo); result = MoveEntryToTrash(&sourceEntry, loc, undo);
@@ -1082,10 +1085,10 @@ class FailWithAlert {
} }
FailWithAlert(status_t error, const char* string, const char* name) FailWithAlert(status_t error, const char* string, const char* name)
: :
fString(string), fString(string),
fName(name), fName(name),
fError(error) fError(error)
{ {
} }
@@ -1094,20 +1097,22 @@ class FailWithAlert {
status_t fError; status_t fError;
}; };
class MoveError { class MoveError {
public: public:
static void FailOnError(status_t error) static void FailOnError(status_t error)
{ {
if (error != B_OK) if (error != B_OK)
throw MoveError(error); throw MoveError(error);
} }
MoveError(status_t error) MoveError(status_t error)
: fError(error) :
{ fError(error)
} {
}
status_t fError; status_t fError;
}; };
@@ -1273,12 +1278,17 @@ LowLevelCopy(BEntry* srcEntry, StatStruct* srcStat, BDirectory* destDir,
get_system_info(&sinfo); get_system_info(&sinfo);
size_t freesize = static_cast<size_t>( size_t freesize = static_cast<size_t>(
(sinfo.max_pages - sinfo.used_pages) * B_PAGE_SIZE); (sinfo.max_pages - sinfo.used_pages) * B_PAGE_SIZE);
bufsize = freesize / 4; // take 1/4 of RAM max bufsize = freesize / 4;
bufsize -= bufsize % (16* 1024); // Round to 16 KB boundaries // take 1/4 of RAM max
if (bufsize < kMinBufferSize) // at least kMinBufferSize bufsize -= bufsize % (16* 1024);
// Round to 16 KB boundaries
if (bufsize < kMinBufferSize) {
// at least kMinBufferSize
bufsize = kMinBufferSize; bufsize = kMinBufferSize;
else if (bufsize > kMaxBufferSize) // no more than kMaxBufferSize } else if (bufsize > kMaxBufferSize) {
// no more than kMaxBufferSize
bufsize = kMaxBufferSize; bufsize = kMaxBufferSize;
}
} }
BFile destFile(destDir, destName, O_RDWR | O_CREAT); BFile destFile(destDir, destName, O_RDWR | O_CREAT);
@@ -1589,9 +1599,8 @@ 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;
@@ -1726,6 +1735,7 @@ MoveItem(BEntry* entry, BDirectory* destDir, BPoint* loc, uint32 moveMode,
loopControl->UpdateStatus(ref.name, ref, 1); loopControl->UpdateStatus(ref.name, ref, 1);
if (entry->IsDirectory()) if (entry->IsDirectory())
return RecursiveMove(entry, destDir, loopControl); return RecursiveMove(entry, destDir, loopControl);
MoveError::FailOnError(entry->MoveTo(destDir, newName)); MoveError::FailOnError(entry->MoveTo(destDir, newName));
} else { } else {
bool makeOriginalName = (moveMode == kDuplicateSelection); bool makeOriginalName = (moveMode == kDuplicateSelection);
@@ -3695,8 +3705,10 @@ LaunchBrokenLink(const char* signature, const BMessage* refs)
return B_OK; return B_OK;
} }
// external launch calls; need to be robust, work if Tracker is not running // external launch calls; need to be robust, work if Tracker is not running
#if !B_BEOS_VERSION_DANO #if !B_BEOS_VERSION_DANO
_IMPEXP_TRACKER _IMPEXP_TRACKER
#endif #endif
@@ -3717,7 +3729,7 @@ FSOpenWith(BMessage* listOfRefs)
status_t result = B_ERROR; status_t result = B_ERROR;
listOfRefs->what = B_REFS_RECEIVED; listOfRefs->what = B_REFS_RECEIVED;
if (dynamic_cast<TTracker*>(be_app)) if (dynamic_cast<TTracker*>(be_app) != NULL)
result = TrackerOpenWith(listOfRefs); result = TrackerOpenWith(listOfRefs);
else else
ASSERT(!"not yet implemented"); ASSERT(!"not yet implemented");
@@ -3725,8 +3737,10 @@ FSOpenWith(BMessage* listOfRefs)
return result; return result;
} }
// legacy calls, need for compatibility // legacy calls, need for compatibility
void void
FSOpenWithDocuments(const entry_ref* executable, BMessage* documents) FSOpenWithDocuments(const entry_ref* executable, BMessage* documents)
{ {
@@ -3734,12 +3748,13 @@ FSOpenWithDocuments(const entry_ref* executable, BMessage* documents)
delete documents; delete documents;
} }
status_t status_t
FSLaunchUsing(const entry_ref* ref, BMessage* listOfRefs) FSLaunchUsing(const entry_ref* ref, BMessage* listOfRefs)
{ {
BMessage temp(B_REFS_RECEIVED); BMessage temp(B_REFS_RECEIVED);
if (listOfRefs == NULL) { if (listOfRefs == NULL) {
ASSERT(ref); ASSERT(ref != NULL);
temp.AddRef("refs", ref); temp.AddRef("refs", ref);
listOfRefs = &temp; listOfRefs = &temp;
} }
@@ -3748,6 +3763,7 @@ FSLaunchUsing(const entry_ref* ref, BMessage* listOfRefs)
return B_OK; return B_OK;
} }
status_t status_t
FSLaunchItem(const entry_ref* ref, BMessage* message, int32, bool async) FSLaunchItem(const entry_ref* ref, BMessage* message, int32, bool async)
{ {
+1 -1
View File
@@ -37,13 +37,13 @@ All rights reserved.
#include <FindDirectory.h> #include <FindDirectory.h>
#include <List.h> #include <List.h>
#include <ObjectList.h>
#include <Point.h> #include <Point.h>
#include <StorageDefs.h> #include <StorageDefs.h>
#include <vector> #include <vector>
#include "Model.h" #include "Model.h"
#include "ObjectList.h"
// APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup // APIs/code in FSUtils.h and FSUtils.cpp is slated for a major cleanup