Item2005: Func::moveAttachment appears to be corrupting topics.

pencil
Priority: Urgent
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Engine
Component: Store
Branches:
Reported By: GeorgeClark
Waiting For:
Last Change By: CrawfordCurrie
The DirectedGraphPlugin uses Func::moveAttachment to delete attachments for unneeded formats. After this runs, the topic is reduced to a single line of META information. No other topic data or attachment metadata survives.

The code in the DirectedGraphPlugin is:

            Foswiki::Func::moveAttachment( $web, $topic, $fn,
                $Foswiki::cfg{TrashWebName},
                'TrashAttachment', "$web.$topic.$of" );

If I change the DirectedGraphPlugin to use direct file I/O, the plugin uses perl unlink to remove the attachments, and the corrupted topics don't occur.

No errors are logged.

To recreate the problem, create a very simple directed graph with 2 output formats. Then delete one of the output formats and save the topic. (in the below example, remove the vectorformats="jpg" parameter. The topic.txt file will now contain only the first META line.

<dot map="1" inline="svg" vectorformats="jpg">
digraph G {
    URL="http://foswiki.org";
    Plugins [URL="http://foswiki.org/Extensions"];
    DirectedGraphPlugin [URL="http://foswiki.org/Extensions/DirectedGraphPlugin"];
    Plugins -> DirectedGraphPlugin;
}
</dot>

This problem does not happen on foswiki 1.0.6 using the same plugin code.

-- GeorgeClark - 06 Sep 2009

I've confirmed this and added at testcase to the FuncTests.pm Test the content of the "SourceTopic" before and after the move. It starts containing the word "wibble" and should continue to contain that after the attachment move. Fails on trunk, works on 1.0.6

Note that the problem only occurrs when moving the attachment from one topic to another. The 2nd test, renaming an attachment by moving it to a new name under the same Topic appears to not corrupt the topic.

-- GeorgeClark - 07 Sep 2009

I believe that the issue is that Func.pm uses the "new" method for the Meta object when it should use "load" so that the existing topic is loaded into the meta object.
-    my $from = Foswiki::Meta->new( $Foswiki::Plugins::SESSION, $web, $topic );
+    my $from = Foswiki::Meta->load( $Foswiki::Plugins::SESSION, $web, $topic );

With this change the source topic is no longer corrupted. But the attachment is still not moved correctly so something more is going on.

The issue is that when renaming an attachment, only a single meta object should be created. otherwise if from and to are 2 copies of the same object, changes made to one copy are lost when the 2nd copy is failed.

I've checked in fixes - unit tests now run. And DirectedGraphPlugin is not corrupting topics when attachments are removed.

Crawford - could you check it over please.

-- GeorgeClark - 14 Sep 2009

Looks good to me.

-- CrawfordCurrie - 19 Sep 2009

ItemTemplate edit

Summary Func::moveAttachment appears to be corrupting topics.
ReportedBy GeorgeClark
Codebase trunk
SVN Range Foswiki-1.1.0-dev, Thu, 03 Sep 2009, build 4764
AppliesTo Engine
Component Store
Priority Urgent
CurrentState Closed
WaitingFor
Checkins distro:6c1e39ec784f distro:942b9d3d36ac distro:c87e253162ee distro:42ccdbdea122 distro:eab279e61b3a distro:3d408b08a0ac
TargetRelease minor
ReleasedIn 1.1.0
Topic revision: r13 - 06 Sep 2010, CrawfordCurrie
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy