The DataEditor now has a separate entry_ref for attributes - that's used

to have access to the attributes of a root directory. Internally, only
this ref is used when accessing attribute data.
Also fixed an initialization bug in case the stream couldn't be properly
opened; some values were just set too late (could lead to strange things
as well as a crash).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10481 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-12-17 08:34:34 +00:00
parent 6f633eb2a6
commit 9e98ea36fd
2 changed files with 20 additions and 19 deletions

View File

@ -399,17 +399,21 @@ status_t
DataEditor::SetTo(BEntry &entry, const char *attribute)
{
fSize = 0;
fLastChange = fFirstChange = NULL;
fChangesFromSaved = 0;
fView = NULL;
fRealViewOffset = 0;
fViewOffset = 0;
fRealViewSize = fViewSize = fBlockSize = 512;
struct stat stat;
stat.st_mode = 0;
status_t status = entry.GetStat(&stat);
if (status < B_OK)
return status;
bool isFileSystem = false;
entry.GetRef(&fAttributeRef);
fBlockSize = 512;
bool isFileSystem = false;
if (entry.IsDirectory()) {
// we redirect root directories to their volumes
@ -443,7 +447,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
fIsReadOnly = false;
entry.GetRef(&fRef);
fIsDevice = S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode);
if (attribute != NULL)
@ -452,8 +455,9 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
fAttribute = NULL;
if (IsAttribute()) {
BNode node(&fAttributeRef);
attr_info info;
status = fFile.GetAttrInfo(fAttribute, &info);
status = node.GetAttrInfo(fAttribute, &info);
if (status != B_OK) {
fFile.Unset();
return status;
@ -488,11 +492,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
}
}
fLastChange = fFirstChange = NULL;
fChangesFromSaved = 0;
fView = NULL;
fRealViewOffset = 0;
fViewOffset = 0;
fRealViewSize = fViewSize = fBlockSize;
fNeedsUpdate = true;
@ -921,9 +920,10 @@ status_t
DataEditor::Update()
{
ssize_t bytesRead;
if (IsAttribute())
bytesRead = fFile.ReadAttr(fAttribute, fType, fRealViewOffset, fView, fRealViewSize);
else
if (IsAttribute()) {
BNode node(&fAttributeRef);
bytesRead = node.ReadAttr(fAttribute, fType, fRealViewOffset, fView, fRealViewSize);
} else
bytesRead = fFile.ReadAt(fRealViewOffset, fView, fRealViewSize);
if (bytesRead < B_OK)

View File

@ -1,7 +1,7 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef DATA_EDITOR_H
#define DATA_EDITOR_H
@ -78,6 +78,7 @@ class DataEditor : public BLocker {
BMessenger progressMessenger, volatile bool *stop = NULL);
BFile &File() { return fFile; }
const entry_ref &AttributeRef() const { return fAttributeRef; }
const entry_ref &Ref() const { return fRef; }
private:
@ -94,7 +95,7 @@ class DataEditor : public BLocker {
BObjectList<BMessenger> fObservers;
entry_ref fRef;
entry_ref fRef, fAttributeRef;
BFile fFile;
const char *fAttribute;
type_code fType;