|
29 | 29 | import org.labkey.api.audit.AuditTypeEvent; |
30 | 30 | import org.labkey.api.audit.provider.FileSystemAuditProvider; |
31 | 31 | import org.labkey.api.collections.CaseInsensitiveHashSet; |
| 32 | +import org.labkey.api.data.Container; |
32 | 33 | import org.labkey.api.data.SimpleFilter; |
33 | 34 | import org.labkey.api.data.TableInfo; |
34 | 35 | import org.labkey.api.exp.api.ExpData; |
@@ -589,30 +590,35 @@ public boolean delete(User user) |
589 | 590 | if (file == null || (null != user && !canDelete(user, true, null))) |
590 | 591 | return false; |
591 | 592 |
|
592 | | - try { |
593 | | - FileContentService svc = FileContentService.get(); |
594 | | - AttachmentDirectory dir; |
595 | | - dir = svc.getMappedAttachmentDirectory(getContainer(), false); |
596 | | - String fileDirPath = file.getParent(); |
597 | | - |
598 | | - // 23746: If file exists in parent with the same name it was deleted instead |
599 | | - if (dir != null && fileDirPath != null && dir.getFileSystemDirectoryPath().toAbsolutePath().toString().equals(fileDirPath)) |
| 593 | + // Resources that aren't in a container (e.g., module resources) can't have legacy file attachments |
| 594 | + Container c = getContainer(); |
| 595 | + if (c != null) |
| 596 | + { |
| 597 | + try |
600 | 598 | { |
601 | | - // legacy support for files added through the narrow files web part but deleted through |
602 | | - // the newer file browser (issue: 11396). This is the difference between files stored through |
603 | | - // webdav or via the attachments service. |
604 | | - // |
605 | | - Attachment attach = AttachmentService.get().getAttachment(dir, file.getName()); |
606 | | - if (attach != null) |
| 599 | + FileContentService svc = FileContentService.get(); |
| 600 | + AttachmentDirectory dir = svc.getMappedAttachmentDirectory(c, false); |
| 601 | + String fileDirPath = file.getParent(); |
| 602 | + |
| 603 | + // 23746: If file exists in parent with the same name it was deleted instead |
| 604 | + if (dir != null && fileDirPath != null && dir.getFileSystemDirectoryPath().toAbsolutePath().toString().equals(fileDirPath)) |
607 | 605 | { |
608 | | - AttachmentService.get().deleteAttachment(dir, file.getName(), null); |
609 | | - return (AttachmentService.get().getAttachment(dir, file.getName()) == null); |
| 606 | + // legacy support for files added through the narrow files web part but deleted through |
| 607 | + // the newer file browser (issue: 11396). This is the difference between files stored through |
| 608 | + // webdav or via the attachments service. |
| 609 | + // |
| 610 | + Attachment attach = AttachmentService.get().getAttachment(dir, file.getName()); |
| 611 | + if (attach != null) |
| 612 | + { |
| 613 | + AttachmentService.get().deleteAttachment(dir, file.getName(), null); |
| 614 | + return (AttachmentService.get().getAttachment(dir, file.getName()) == null); |
| 615 | + } |
610 | 616 | } |
611 | 617 | } |
612 | | - } |
613 | | - catch (Exception e) |
614 | | - { |
615 | | - _log.error(e); |
| 618 | + catch (Exception e) |
| 619 | + { |
| 620 | + _log.error(e); |
| 621 | + } |
616 | 622 | } |
617 | 623 | boolean deleted = file.delete(); |
618 | 624 | if (!deleted) |
|
0 commit comments