You are here: Foswiki>Tasks Web>Item2003 (10 Sep 2009, GeorgeClark)Edit Attach

Item2003: Foswiki::Func attachment API's fail hard if attached file is missing

pencil
Priority: Urgent
Current State: Closed
Released In:
Target Release: n/a
Applies To: Engine
Component: Store
Branches:
Reported By: GeorgeClark
Waiting For: Main.GeorgeClark
Last Change By: GeorgeClark
If a plugin uses the Foswiki::Func::attachmentExists or readAttachment routines, they fail hard if the attachment file is not found.

Foswiki detected an internal error - please check your Foswiki logs and webserver logs for more information.

VC::Handler: stream open path failed: No such file or directory

Apache Log reports:

VC::Handler: stream open /var/www/SVN/foswiki/core/pub/System/DirectedGraphPlugin/DirectedGraphPlugin_2.cmapx failed: No such file or directory at /var/www/SVN/foswiki/core/lib/Foswiki/Store/VC/Handler.pm line 1011.

According to Foswiki::Func, "If the attachment does not exist, or cannot be read, undef will be returned." This appears to no longer function in this manner, and using the attachmentExists API to bypass the trouble fails with the same error. Code in DirectedGraphPlugin that encounters the problem:

    if (Foswiki::Func::attachmentExists( $web, $topic, "$outFilename.cmapx")) {
        $mapfile = Foswiki::Func::readAttachment( $web, $topic, "$outFilename.cmapx" ) ;
        }
The attachmentExists call was added locally to try to avoid the problem but the failure still occurs.

A quick review of the FuncTests.pm - the attachment tests don't validate the attachmentExists function, or the case where readAttachment encounters a missing attachment.

The following additional tests will show the issue on core - they work on the release branch. The last of the 3 tests fails on core and results in the VC::Handler error.

    # This should succeed - attachment exists
    $this->assert(
        Foswiki::Func::attachmentExists( $this->{test_web}, $topic, $name1 ) );

    # This should fail - attachment is not present
    $this->assert(
        !(Foswiki::Func::attachmentExists( $this->{test_web}, $topic, "NotExists" )) );

    # This should fail - attachment is not present
    $this->assert(
        !Foswiki::Func::readAttachment( $this->{test_web}, $topic, "NotExists" ));


George, I fixed readAttachment, but I can't find anything wrong with attachmentExists - can you clarify? If it's not broken, please set this to Closed.

-- CrawfordCurrie - 10 Sep 2009

Changing to closed. Testing attachmentExists in my plugin didn't seem to bypass the problem. But the testcases I wrote said that indeed attachmentExists is working correctly.

-- GeorgeClark - 10 Sep 2009

Is this a trunk only issue?

I do not see the target release set.

-- KennethLavrsen - 10 Sep 2009

Trunk only. I checked in the same tests into Release, but they worked there.

-- GeorgeClark - 10 Sep 2009

ItemTemplate edit

Summary Foswiki::Func attachment API's fail hard if attached file is missing
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 GeorgeClark
Checkins distro:70184141727e distro:3bbaecd5af64 distro:813fea42aaa5
TargetRelease n/a
ReleasedIn
Topic revision: r7 - 10 Sep 2009, GeorgeClark
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