Skip to content

AtomicMoveNotSupportedException with atomicMove in MSIX environment on another drive #1824

Description

@Thomas-Vos

The atomicMove function seems to consistently throw an exception when using within an MSIX app on another disk (not C:).

How to reproduce:

  1. Have an MSIX app installed on another drive (not C:). (probably a java with the correct manifest for java apps?) (If you do not have another disk, just create a virtual drive under Settings, System, Storage, Disk & volumes, Create a virtual hard disk (VHD). It will mount as a new drive letter. Then you can move the msix app to it.)
Image
  1. Open a Terminal or PowerShell and execute this to open a command prompt within the virtual MSIX environment (replace TODO with your app details)

Invoke-CommandInDesktopPackage -Command cmd.exe -PreventBreakaway -PackageFamilyName TODO_TODO -AppId TODO

Example in my case (you could just use the container of my app from the Microsoft Store as it is setup for java apps):

Invoke-CommandInDesktopPackage -Command cmd.exe -PreventBreakaway -PackageFamilyName HueEssentials.HueEssentials_yfdreesr38bg8 -AppId HueEssentials

  1. Now create a simple Kotlin project with this as main function:
import okio.FileSystem
import okio.Path.Companion.toOkioPath
import java.io.File

fun main() {
   val a = File(System.getenv("APPDATA"), "testing/a.txt")
   a.parentFile.mkdirs()
   FileSystem.SYSTEM.write(a.toOkioPath()) {
       writeUtf8("testing")
   }
   val b = File(System.getenv("APPDATA"), "testing/b.txt")
   b.delete()
   FileSystem.SYSTEM.atomicMove(a.toOkioPath(), b.toOkioPath())
}
  1. Build a jar file for the above

  2. After that, open the command prompt from step 2 and run the jar (java -jar ..)

  3. On my machine I get this consistently:

C:\Users\Thomas\IdeaProjects\untitled1>java -jar build\libs\untitled1-fat-1.0-SNAPSHOT.jar
Exception in thread "main" java.nio.file.AtomicMoveNotSupportedException: C:\Users\Thomas\AppData\Roaming\testing\a.txt -> C:\Users\Thomas\AppData\Roaming\testing\b.txt: The system cannot move the file to a different disk drive
        at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:308)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
        at java.base/java.nio.file.Files.move(Files.java:1319)
        at okio.NioSystemFileSystem.atomicMove(NioSystemFileSystem.kt:78)
        at org.example.MainKt.main(Main.kt:17)
        at org.example.MainKt.main(Main.kt)

C:\Users\Thomas\IdeaProjects\untitled1>

It seems atomicMove fails even though it should be moved on one disk (I think). The MSIX app container I am running this in was installed on another drive, but Windows seems to be creating virtualized C disk paths. This is probably the cause of the issue.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions