@@ -77,22 +77,48 @@ public override IAsyncAction CopyAndReplaceAsync(IStorageFile fileToReplace)
77
77
78
78
public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder )
79
79
{
80
- return File . MoveAsync ( destinationFolder ) ;
80
+ return MoveAsync ( destinationFolder , Name , NameCollisionOption . FailIfExists ) ;
81
81
}
82
82
83
83
public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder , string desiredNewName )
84
84
{
85
- return File . MoveAsync ( destinationFolder , desiredNewName ) ;
85
+ return MoveAsync ( destinationFolder , desiredNewName , NameCollisionOption . FailIfExists ) ;
86
86
}
87
87
88
88
public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder , string desiredNewName , NameCollisionOption option )
89
89
{
90
- return File . MoveAsync ( destinationFolder , desiredNewName , option ) ;
90
+ return AsyncInfo . Run ( async ( cancellationToken ) =>
91
+ {
92
+ var destFolder = destinationFolder . AsBaseStorageFolder ( ) ; // Avoid calling IStorageFolder method
93
+ if ( destFolder is SystemStorageFolder sysFolder )
94
+ {
95
+ // File created by CreateFileAsync will get immediately deleted on MTP?! (#7206)
96
+ await File . MoveAsync ( sysFolder . Folder , desiredNewName , option ) ;
97
+ return ;
98
+ }
99
+ var destFile = await destFolder . CreateFileAsync ( desiredNewName , option . Convert ( ) ) ;
100
+ using ( var inStream = await this . OpenStreamForReadAsync ( ) )
101
+ using ( var outStream = await destFile . OpenStreamForWriteAsync ( ) )
102
+ {
103
+ await inStream . CopyToAsync ( outStream ) ;
104
+ await outStream . FlushAsync ( ) ;
105
+ }
106
+ // Move unsupported, copy but do not delete original
107
+ } ) ;
91
108
}
92
109
93
110
public override IAsyncAction MoveAndReplaceAsync ( IStorageFile fileToReplace )
94
111
{
95
- return File . MoveAndReplaceAsync ( fileToReplace ) ;
112
+ return AsyncInfo . Run ( async ( cancellationToken ) =>
113
+ {
114
+ using ( var inStream = await this . OpenStreamForReadAsync ( ) )
115
+ using ( var outStream = await fileToReplace . OpenStreamForWriteAsync ( ) )
116
+ {
117
+ await inStream . CopyToAsync ( outStream ) ;
118
+ await outStream . FlushAsync ( ) ;
119
+ }
120
+ // Move unsupported, copy but do not delete original
121
+ } ) ;
96
122
}
97
123
98
124
public override string ContentType => File . ContentType ;
0 commit comments