Bug 157448 - Setting MailMerge.OutputURL to "MyDocuments" URL on Windows produces "URL is read-only" error
Summary: Setting MailMerge.OutputURL to "MyDocuments" URL on Windows produces "URL is ...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All Windows (All)
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:24.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-26 06:46 UTC by Mike Kaganski
Modified: 2023-09-26 10:00 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2023-09-26 06:46:06 UTC
Consider this BASIC code:

Sub TestMMOutput()
  wshshell = CreateObject("WScript.Shell")
  sDocsPath = wshShell.SpecialFolders.Item("MyDocuments")
  sDocsURL = ConvertToURL(sDocsPath)
  oMailMerge = CreateUnoService("com.sun.star.text.MailMerge")
  oMailMerge.OutputURL = sDocsURL
End Sub

Running this code on Windows results in this error message:

BASIC runtime error.
An exception occurred 
Type: com.sun.star.lang.IllegalArgumentException
Message: URL is read-only: file:///D:/Documents.

This error is produced because SwXMailMerge::setPropertyValue calls UCB_IsReadOnlyFileName, and the latter returns the result based on what filesystem attributes tell (the actual work is done in osl_getFileStatus); but as mentioned in MS documentation [1], [2], FILE_ATTRIBUTE_READONLY "is not honored on directories" - so it must be ignored on Windows, by removing this flag when it's a directory.

[1] https://learn.microsoft.com/en-us/windows/desktop/FileIO/file-attribute-constants
[2] https://support.microsoft.com/kb/326549
Comment 1 Commit Notification 2023-09-26 10:00:06 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d724b51c7da391c9afe5e47476d432aecf1c4c67

tdf#157448: ignore FILE_ATTRIBUTE_READONLY when FILE_ATTRIBUTE_DIRECTORY is set

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.