* fixed two bugs related to #1445, on BeOS R5, BFS has a bug that prevents

attributes to be written under a certain name when they already exist under
  the same name but with a different type
* the code that did the saving to a temporary file, then copied the attributes
  of the original file, then clobbered the original file prevented saving the
  icon in the icon attribute reliably, disabled this code for now and added
  TODO how it should work better


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22205 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-09-08 18:25:06 +00:00
parent 5725361ffe
commit 129302e4c1
2 changed files with 75 additions and 57 deletions

View File

@ -127,29 +127,32 @@ status_t
Exporter::_Export(const Icon* icon,
const entry_ref* docRef)
{
// TODO: reenable the commented out code, but make it work
// the opposite direction, ie *copy* the file contents
BEntry entry(docRef, true);
if (entry.IsDirectory())
return B_BAD_VALUE;
const entry_ref* ref = docRef;
entry_ref tempRef;
if (entry.Exists()) {
// if the file exists create a temporary file in the same folder
// and hope that it doesn't already exist...
BPath tempPath(docRef);
if (tempPath.GetParent(&tempPath) >= B_OK) {
BString helper(docRef->name);
helper << system_time();
if (tempPath.Append(helper.String()) >= B_OK
&& entry.SetTo(tempPath.Path()) >= B_OK
&& entry.GetRef(&tempRef) >= B_OK) {
// have the output ref point to the temporary
// file instead
ref = &tempRef;
}
}
}
// entry_ref tempRef;
//
// if (entry.Exists()) {
// // if the file exists create a temporary file in the same folder
// // and hope that it doesn't already exist...
// BPath tempPath(docRef);
// if (tempPath.GetParent(&tempPath) >= B_OK) {
// BString helper(docRef->name);
// helper << system_time();
// if (tempPath.Append(helper.String()) >= B_OK
// && entry.SetTo(tempPath.Path()) >= B_OK
// && entry.GetRef(&tempRef) >= B_OK) {
// // have the output ref point to the temporary
// // file instead
// ref = &tempRef;
// }
// }
// }
status_t ret = B_BAD_VALUE;
@ -175,43 +178,47 @@ Exporter::_Export(const Icon* icon,
}
outFile.Unset();
if (ret < B_OK && ref != docRef) {
// in case of failure, remove temporary file
entry.Remove();
}
if (ret >= B_OK && ref != docRef) {
// move temp file overwriting actual document file
BEntry docEntry(docRef, true);
// copy attributes of previous document file
BNode sourceNode(&docEntry);
BNode destNode(&entry);
if (sourceNode.InitCheck() >= B_OK && destNode.InitCheck() >= B_OK) {
// lock the nodes
if (sourceNode.Lock() >= B_OK) {
if (destNode.Lock() >= B_OK) {
// iterate over the attributes
char attrName[B_ATTR_NAME_LENGTH];
while (sourceNode.GetNextAttrName(attrName) >= B_OK) {
attr_info info;
if (sourceNode.GetAttrInfo(attrName, &info) >= B_OK) {
char *buffer = new (nothrow) char[info.size];
if (buffer && sourceNode.ReadAttr(attrName, info.type, 0,
buffer, info.size) == info.size) {
destNode.WriteAttr(attrName, info.type, 0,
buffer, info.size);
}
delete[] buffer;
}
}
destNode.Unlock();
}
sourceNode.Unlock();
}
}
// clobber the orginal file with the new temporary one
ret = entry.Rename(docRef->name, true);
}
// if (ret < B_OK && ref != docRef) {
// // in case of failure, remove temporary file
// entry.Remove();
// }
//
// if (ret >= B_OK && ref != docRef) {
// // move temp file overwriting actual document file
// BEntry docEntry(docRef, true);
// // copy attributes of previous document file
// BNode sourceNode(&docEntry);
// BNode destNode(&entry);
// if (sourceNode.InitCheck() >= B_OK && destNode.InitCheck() >= B_OK) {
// // lock the nodes
// if (sourceNode.Lock() >= B_OK) {
// if (destNode.Lock() >= B_OK) {
// // iterate over the attributes
// char attrName[B_ATTR_NAME_LENGTH];
// while (sourceNode.GetNextAttrName(attrName) >= B_OK) {
//// // skip the icon, since we probably wrote that
//// // before
//// if (strcmp(attrName, "BEOS:ICON") == 0)
//// continue;
// attr_info info;
// if (sourceNode.GetAttrInfo(attrName, &info) >= B_OK) {
// char *buffer = new (nothrow) char[info.size];
// if (buffer && sourceNode.ReadAttr(attrName, info.type, 0,
// buffer, info.size) == info.size) {
// destNode.WriteAttr(attrName, info.type, 0,
// buffer, info.size);
// }
// delete[] buffer;
// }
// }
// destNode.Unlock();
// }
// sourceNode.Unlock();
// }
// }
// // clobber the orginal file with the new temporary one
// ret = entry.Rename(docRef->name, true);
// }
if (ret >= B_OK && MIMEType()) {
// set file type

View File

@ -105,15 +105,26 @@ FlatIconExporter::Export(const Icon* icon, BNode* node,
// flatten icon
status_t ret = _Export(buffer, icon);
if (ret < B_OK)
if (ret < B_OK) {
printf("failed to export to buffer: %s\n", strerror(ret));
return ret;
}
#ifndef __HAIKU__
// work arround a BFS bug, attributes with the same name but different
// type fail to be written
node->RemoveAttr(attrName);
#endif
// write buffer to attribute
ssize_t written = node->WriteAttr(attrName, B_VECTOR_ICON_TYPE, 0,
buffer.Buffer(), buffer.SizeUsed());
if (written != (ssize_t)buffer.SizeUsed()) {
if (written < 0)
if (written < 0) {
printf("failed to write attribute: %s\n", strerror((status_t)written));
return (status_t)written;
}
printf("failed to write attribute\n");
return B_ERROR;
}