--- modules/attachment/attachment.module 2006-03-22 13:38:19.000000000 +0700 +++ modules/attachment/attachment.module 2006-05-01 17:24:34.000000000 +0700 @@ -41,7 +41,7 @@ foreach ((array)$node->attachments as $attachment) { if (!$attachment['deleted']) { module_invoke('filemanager', 'promote_working', $attachment['fid']); - if ($attachment['aid']) { + if ($attachment['aid'] || $attachment['aid']=db_result(db_query("SELECT aid FROM {attachment} WHERE nid = %d AND filename = '%s' LIMIT 1", $node->nid, $attachment['filename']))) { db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['aid']); } else { @@ -50,7 +50,8 @@ } } else { - module_invoke('filemanager', 'delete', $attachment['fid']); + if (db_result(db_query("SELECT COUNT(*) FROM {attachment} WHERE nid = %d AND filename = '%s'", $node->nid, $attachment['filename'])) <=1) + module_invoke('filemanager', 'delete', $attachment['fid']); if ($attachment['aid']) { db_query("DELETE FROM {attachment} WHERE aid=%d",$attachment['aid']); }