Skip to content

Disable Move operation on folders when using StorageFile APIs #8960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ await DialogDisplayHelper.ShowDialogAsync(

if (fsResult)
{
var fsResultMove = await FilesystemTasks.Wrap(() => MoveDirectoryAsync((BaseStorageFolder)fsSourceFolder, (BaseStorageFolder)fsDestinationFolder, fsSourceFolder.Result.Name, collision.Convert(), true));
// Moving folders using Storage API can result in data loss, copy instead
//var fsResultMove = await FilesystemTasks.Wrap(() => MoveDirectoryAsync((BaseStorageFolder)fsSourceFolder, (BaseStorageFolder)fsDestinationFolder, fsSourceFolder.Result.Name, collision.Convert(), true));
var fsResultMove = new FilesystemResult<BaseStorageFolder>(null, FileSystemStatusCode.Generic);
if (await DialogDisplayHelper.ShowDialogAsync("ErrorDialogThisActionCannotBeDone".GetLocalized(), "ErrorDialogUnsupportedMoveOperation".GetLocalized(), "OK", "Cancel".GetLocalized()))
{
fsResultMove = await FilesystemTasks.Wrap(() => CloneDirectoryAsync((BaseStorageFolder)fsSourceFolder, (BaseStorageFolder)fsDestinationFolder, fsSourceFolder.Result.Name, collision.Convert()));
}

if (fsResultMove == FileSystemStatusCode.AlreadyExists)
{
Expand Down Expand Up @@ -749,8 +755,12 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so

if (fsResult)
{
fsResult = await FilesystemTasks.Wrap(() => MoveDirectoryAsync(sourceFolder.Result, destinationFolder.Result, Path.GetFileName(destination),
CreationCollisionOption.FailIfExists, true));
// Moving folders using Storage API can result in data loss, copy instead
//fsResult = await FilesystemTasks.Wrap(() => MoveDirectoryAsync(sourceFolder.Result, destinationFolder.Result, Path.GetFileName(destination), CreationCollisionOption.FailIfExists, true));
if (await DialogDisplayHelper.ShowDialogAsync("ErrorDialogThisActionCannotBeDone".GetLocalized(), "ErrorDialogUnsupportedMoveOperation".GetLocalized(), "OK", "Cancel".GetLocalized()))
{
fsResult = await FilesystemTasks.Wrap(() => CloneDirectoryAsync(sourceFolder.Result, destinationFolder.Result, Path.GetFileName(destination), CreationCollisionOption.FailIfExists));
}
// TODO: we could use here FilesystemHelpers with registerHistory false?
}
errorCode?.Report(fsResult);
Expand Down Expand Up @@ -825,6 +835,7 @@ private async static Task<BaseStorageFolder> CloneDirectoryAsync(BaseStorageFold
return createdRoot;
}

[Obsolete("Moving folders using Storage API can result in data loss. For example hidden folders will not be moved but the parent folder will be deleted at the end. If this happens on a drive without recycle bin StorageDeleteOption.Default results in a permanent delete.")]
private static async Task<BaseStorageFolder> MoveDirectoryAsync(BaseStorageFolder sourceFolder, BaseStorageFolder destinationDirectory, string sourceRootName, CreationCollisionOption collision = CreationCollisionOption.FailIfExists, bool deleteSource = false)
{
BaseStorageFolder createdRoot = await destinationDirectory.CreateFolderAsync(sourceRootName, collision);
Expand Down
24 changes: 20 additions & 4 deletions src/Files.Uwp/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@
<source>Application</source>
<target state="translated">Applicazione</target>
</trans-unit>
<trans-unit id="SystemTimeStye" translate="yes" xml:space="preserve">
<source>System</source>
<target state="translated">Sistema</target>
</trans-unit>
<trans-unit id="NewFolder" translate="yes" xml:space="preserve">
<source>New Folder</source>
<target state="translated">Nuova cartella</target>
Expand Down Expand Up @@ -3522,6 +3518,26 @@ Usiamo App Center per tenere traccia dell'utilizzo dell'app, trovare bug e risol
<source>File is in use</source>
<target state="translated">Il file è in uso</target>
</trans-unit>
<trans-unit id="SystemTimeStyle" translate="yes" xml:space="preserve">
<source>System</source>
<target state="new">System</target>
</trans-unit>
<trans-unit id="Universal" translate="yes" xml:space="preserve">
<source>Universal</source>
<target state="new">Universal</target>
</trans-unit>
<trans-unit id="DateFormatSample" translate="yes" xml:space="preserve">
<source>ex: {0}, {1}</source>
<target state="new">ex: {0}, {1}</target>
</trans-unit>
<trans-unit id="SettingsFilesAndFoldersShowThumbnails" translate="yes" xml:space="preserve">
<source>Show thumbnails</source>
<target state="new">Show thumbnails</target>
</trans-unit>
<trans-unit id="ErrorDialogUnsupportedMoveOperation" translate="yes" xml:space="preserve">
<source>Move operation is not supported in this context. Do you want to copy the items instead?</source>
<target state="translated">L'operazione di spostamento non è supportata in questo contesto. Vuoi copiare gli elementi?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
57 changes: 30 additions & 27 deletions src/Files.Uwp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -2759,4 +2759,7 @@ We use App Center to track which settings are being used, find bugs, and fix cra
<data name="SettingsFilesAndFoldersShowThumbnails" xml:space="preserve">
<value>Show thumbnails</value>
</data>
<data name="ErrorDialogUnsupportedMoveOperation" xml:space="preserve">
<value>Move operation is not supported in this context. Do you want to copy the items instead?</value>
</data>
</root>