You are here: Foswiki>Tasks Web>Item13319 (05 Jul 2015, GeorgeClark)Edit Attach

Item13319: RCS Store AutoAttachPubFiles feature converts all attachments into autoattached files.

pencil
Priority: Urgent
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Extension
Component: RCSStoreContrib
Branches: master
Reported By: GeorgeClark
Waiting For:
Last Change By: GeorgeClark
Enable {RCS}{AutoAttachPubFiles} and visit a topic with attachments. Edit/Save topic. All of the attachments have become auto-attached.

Ex. System/OriginalDocumentGraphics Here is the "diff" looking for the string "ok.gif' facebook.gif is a legitimate auto-attach. It was missing from the meta. But book.gif has been converted into an auto-attachment.

-%META:FILEATTACHMENT{name="book.gif" attr="h" comment="" date="1421599902" path="book.gif" size="361" user="ProjectContributor" version="1"}%
+%META:FILEATTACHMENT{name="book.gif" attr="h" autoattached="1" comment="" date="1415510204" path="book.gif" size="361" user="ProjectContributor" version="1"}%
+%META:FILEATTACHMENT{name="facebook.gif" attr="" autoattached="1" comment="" date="1415510204" path="facebook.gif" size="889" version=""}%


Maybe not. 1.1.9 has the same behaviour. Every attachment is converted to autoattached on save. This doesn't seem right though. I the attachment has not changed, then the META:FILEATTACHMENT really should not change. Leaving it as a blocker for now to discuss.

-- GeorgeClark - 22 Mar 2015

Crawford, I have a patch
  • updates the meta for an attachment if the file is new, or has changes
    • Always writes a version, never version=""
    • Increments the version when an existing attachment timestamp changes.
  • copies over existing meta for unmodified attachments

It doesn't help us much with system topics because we update the timestamps automatically and they are never the same as on disk. The fix also increments the version when autoattaching.

The AutoAttach tests still pass. So looks like there are no tests that validate the negative. ... not auto-attaching unmodified files.

diff --git a/RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm b/RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
index 95a29e1..1010fcb 100644
--- a/RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
+++ b/RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
@@ -1303,8 +1303,8 @@ sub _constructAttributesForAutoAttached {
 
     my %pairs = (
         name    => $file,
-        version => '',
         path    => $file,
+        version => '1',
         size    => $stat->[7],
         date    => $stat->[9],
 
@@ -1352,16 +1352,25 @@ sub synchroniseAttachmentsList {
     }
 
     foreach my $file ( keys %filesListedInPub ) {
-        if ( $filesListedInMeta{$file} ) {
-
+        if (  $filesListedInMeta{$file}
+            && $filesListedInMeta{$file}{date} !=
+            $filesListedInPub{$file}{date} )
+        {
+            # File timestamp of existing file has changed.
             # Bring forward any missing yet wanted attributes
             foreach my $field (qw(comment attr user version)) {
                 if ( $filesListedInMeta{$file}{$field} ) {
                     $filesListedInPub{$file}{$field} =
                       $filesListedInMeta{$file}{$field};
+                    if ( $field eq 'version' ) {
+                        $filesListedInPub{$file}{$field}++;
+                    }
                 }
             }
         }
+        else {
+            $filesListedInPub{$file} = $filesListedInMeta{$file} if ( $filesListedInMeta{$file} );
+        }
     }
 
     # A comparison of the keys of the $filesListedInMeta and %filesListedInPub
@@ -1400,9 +1409,12 @@ sub _getAttachmentStats {
     my $dir            = "$Foswiki::cfg{PubDir}/$this->{web}/$this->{topic}";
     foreach my $attachment ( $this->getAttachmentList() ) {
         my @stat = stat( $dir . "/" . $attachment );
-        $attachmentList{$attachment} =
-          _constructAttributesForAutoAttached( $attachment, \@stat );
+        if ( scalar @stat ) {
+            $attachmentList{$attachment} =
+              _constructAttributesForAutoAttached( $attachment, \@stat );
+        }
     }
+
     return %attachmentList;
 }
 

-- GeorgeClark - 22 Mar 2015

Checking in a fix and unit test changes to show that unmodified files don't get their meta updated, only new / modified files.

-- GeorgeClark - 22 Mar 2015

Found another issue. It "attaches"directories.

-- GeorgeClark - 23 Mar 2015
 

ItemTemplate edit

Summary RCS Store AutoAttachPubFiles feature converts all attachments into autoattached files.
ReportedBy GeorgeClark
Codebase 1.1.9, trunk
SVN Range
AppliesTo Extension
Component RCSStoreContrib
Priority Urgent
CurrentState Closed
WaitingFor
Checkins distro:4531b4a2d911 distro:8736a5411044
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches master
trunkCheckins
masterCheckins distro:4531b4a2d911 distro:8736a5411044
ItemBranchCheckins
Release01x01Checkins
Topic revision: r5 - 05 Jul 2015, GeorgeClark - This page was cached on 10 Dec 2016 - 04:01.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License