-
Notifications
You must be signed in to change notification settings - Fork 426
Writing to package AppData results in broken permissions #2788
Description
Describe the bug
Attempting to write to the packaged app data directory using System.IO or StorageFile from a packaged WinUI 3 Desktop app causes unusual permissions issues. Any files or directories created will have the Archive | Encrypted attributes, despite being neither an archive nor encrypted. Programmatically copying the files into a different, non-AppData directory of course doesn't solve the issue (the file is still "encrypted").
Steps to reproduce the bug
- Clone https://github.com/yoshiask/Repros
- Observe the code in https://github.com/yoshiask/Repros/blob/47570dee79bd80c853be778da66eb36eae726caf/WinAppSdk/WinAppSdk/MainWindow.xaml.cs
- Run the
WinAppSdk (Package)project and look at the debug console output.
or
- Create a new packaged WinUI 3 project
- Use
ApplicationData.Current.LocalFolder.Pathto get the packaged app data directory - Use
File.WriteAllTextorStorageFile.CreateFileAsyncto write to a file in that directory - Observe that the file attributes are
Archive | Encrypted
Expected behavior
Successfully read and write to the packaged app data directory.
Screenshots
No response
NuGet package version
1.1.3, 1.1.2
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 21H2 (22000), Windows 10 version 21H2 (19044, November 2021 Update), Windows 10 version 21H1 (19043, May 2021 Update)
IDE
Visual Studio 2022-preview, Visual Studio 2022
Additional context
This issue effectively means apps can't write to app data at all. File system virtualization for the app data directory is enabled by default for packaged apps, which means even trying to write to %appdata% directly gets redirected to the packaged app data directory. The only workaround I could find (apart from just not writing to App Data) is to disable virtualization, but App Installer refuses to install any package that declares the unvirtualizedResources rescap.
As a side note, my app also declares the packageQuery and packageManagement rescaps. Why does App Installer care that my app can write to the real App Data, but not that it can install any arbitrary package to the user's system? Seems pretty arbitrary to me, but that's a separate problem.