Skip to content

Commit

Permalink
Item9015: Pull in auto-attached files that are missing from metadata.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/AttachmentListPlugin@7396 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed May 14, 2010
1 parent c08d1aa commit 738b6fb
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/Foswiki/Plugins/AttachmentListPlugin.pm
Expand Up @@ -163,12 +163,13 @@ sub _createFileData {
# define value for topic key only if topic
# has META:FILEATTACHMENT data
my $attachments = _getAttachmentsInTopic( $inWeb, $inTopic );
my $attach_files = _getAttachmentList( $inWeb, $inTopic );

_debug("AttachmentListPlugin::_createFileData");
use Data::Dumper;
_debug( "\t attachments=" . Dumper($attachments) );

if ( scalar @$attachments ) {
if ( scalar @$attachments || ( defined $attach_files && scalar @$attach_files) ) {
$inTopicHash->{$inTopic} = ();

foreach my $attachment (@$attachments) {
Expand All @@ -178,6 +179,15 @@ sub _createFileData {
my $fileName = $fd->{name};
$inTopicHash->{$inTopic}{$fileName} = \$fd;
}

foreach my $fileName (@$attach_files) {
unless ($inTopicHash->{$inTopic}{$fileName}) {
my $fd =
Foswiki::Plugins::AttachmentListPlugin::FileData->new( $inWeb,
$inTopic, { name => $fileName, path => $fileName, autoattached => 1} );
$inTopicHash->{$inTopic}{$fileName} = \$fd;
}
}
}
else {

Expand Down Expand Up @@ -332,6 +342,24 @@ sub _getAttachmentsInTopic {

=pod
Returns array of attached files independent of metadata
=cut

sub _getAttachmentList {
my ($web, $topic) = @_;

my $dir = "$Foswiki::cfg{PubDir}/$web/$topic";
my $dh;
my @files;
opendir($dh, $dir) || return ();
@files = grep { !/^[.*_]/ && !/,v$/ } readdir($dh);
closedir($dh);
return \@files;
}

=pod
=cut

sub _formatFileData {
Expand Down

0 comments on commit 738b6fb

Please sign in to comment.