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

View File

@ -105,15 +105,26 @@ FlatIconExporter::Export(const Icon* icon, BNode* node,
// flatten icon // flatten icon
status_t ret = _Export(buffer, 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; 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 // write buffer to attribute
ssize_t written = node->WriteAttr(attrName, B_VECTOR_ICON_TYPE, 0, ssize_t written = node->WriteAttr(attrName, B_VECTOR_ICON_TYPE, 0,
buffer.Buffer(), buffer.SizeUsed()); buffer.Buffer(), buffer.SizeUsed());
if (written != (ssize_t)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; return (status_t)written;
}
printf("failed to write attribute\n");
return B_ERROR; return B_ERROR;
} }