This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit bd412b29bcaa994ef870afa003c0c0470973409a
Author: Alex <spyhunte...@gmail.com>
AuthorDate: Sat Aug 17 11:09:31 2024 -0400

    JSPWIKI-1197 fix for if and when someone, other software (antivirus, etc) 
or a human deletes an attachment from disk and leaves behind a properties file 
in the attachment director for a given wiki page. Before this change jspwiki 
would not boot up in this condition. After it will and simply logs this error 
condition.
---
 .../org/apache/wiki/providers/BasicAttachmentProvider.java | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
 
b/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
index 86c3cf320..ee4b0b054 100644
--- 
a/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
+++ 
b/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
@@ -379,12 +379,12 @@ public class BasicAttachmentProvider implements 
AttachmentProvider {
                     final Attachment att = getAttachmentInfo( page, 
attachmentName, WikiProvider.LATEST_VERSION );
                     //  Sanity check - shouldn't really be happening, unless 
you mess with the repository directly.
                     if( att == null ) {
-                        throw new ProviderException( "Attachment disappeared 
while reading information:"
-                                + " if you did not touch the repository, there 
is a serious bug somewhere. " + "Attachment = " + attachment
+                        LOG.error( "Attachment disappeared while reading 
information:"
+                                + " if you did not touch the repository, there 
is a serious bug somewhere or perhaps it"
+                                + " was deleted by antivirus software, etc. " 
+ "Attachment = " + attachment
                                 + ", decoded = " + attachmentName );
-                    }
-
-                    result.add( att );
+                    } else 
+                        result.add( att );
                 }
             }
         }
@@ -408,7 +408,9 @@ public class BasicAttachmentProvider implements 
AttachmentProvider {
     public List< Attachment > listAllChanged( final Date timestamp ) throws 
ProviderException {
         final File attDir = new File( m_storageDir );
         if( !attDir.exists() ) {
-            throw new ProviderException( "Specified attachment directory " + 
m_storageDir + " does not exist!" );
+            if (!attDir.mkdirs()) {
+                throw new ProviderException( "Specified attachment directory " 
+ m_storageDir + " does not exist!" );
+            }
         }
 
         final ArrayList< Attachment > list = new ArrayList<>();

Reply via email to