Skip to content
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

Fix rename file issue #1335

Merged
merged 1 commit into from
May 27, 2019
Merged

Fix rename file issue #1335

merged 1 commit into from
May 27, 2019

Conversation

AdrianSoundy
Copy link
Member

@AdrianSoundy AdrianSoundy commented May 25, 2019

Description

With Internal drive on ESP32 the GetFiles was adding adding an extra "\" in path which caused rename to fail. I think this is because a \ is seen as part of filename.

Could also be a problem with STM32

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: adriansoundy adriansoundy@gmail.com

With Internal drive on ESP32 the GetFles was adding adding an exra "\" in path which caused rename to fail. I think this is because a \ is seen as part of filename.
@nfbot
Copy link
Member

nfbot commented May 25, 2019

Hi @AdrianSoundy,

I'm nanoFramework bot.
Thank you for your contribution!

A human will be reviewing it shortly. 😉

@AdrianSoundy
Copy link
Member Author

Sample code that was causing problem.

            StorageFolder internalDevices = Windows.Storage.KnownFolders.InternalDevices;

            var internalDrives = internalDevices.GetFolders();

            StorageFolder Sfolder = internalDrives[0];

            var iFile = Sfolder.CreateFile("test.txt", CreationCollisionOption.ReplaceExisting);

            
            FileIO.WriteText(iFile, "Hello from Esp32");

            var Files = Sfolder.GetFiles();

            foreach (var File in Files)
            {
                Console.WriteLine("Filename-> " + File.Name);
                Console.WriteLine("Path-> " + File.Path);

                if (File.Name == "test.txt")
                {
                    // This produces an exception CLR_E_FILE_NOT_FOUND 
                    File.Rename("text1.txt");

                    // This works
                    //    var ifile = StorageFile.GetFileFromPath(Sfolder.Path + "test.txt");
                    //    ifile.Rename("test1.txt");

                }
                if (File.Name == "text1.txt")
                {
                    File.Delete();
                }

            }

@josesimoes josesimoes added Series: ESP32 Everything related specifically with ESP32 series targets Type: bug labels May 25, 2019
@josesimoes
Copy link
Member

Nice catch @AdrianSoundy ! 👏

Let me check on the STM32 targets before we have this one merged.

@AdrianSoundy
Copy link
Member Author

AdrianSoundy commented May 26, 2019

The problem was reported by DWeaver directly to me.

I think with FatFS it ignores any extra "\"
The problem happens when you combine a drive letter with a filename
I:\ + test1.txt = I:\\test1.txt , the code was adding the separator \ which already existed
When in a folder the separator it is needed.
C:\folder + test1.txt = C:\Folder\test1.txt

For Esp32 we convert to internal VFS path
I:\\test1.txt -> \I\\test1.txt which should have been \I\test1.txt
So filename ended up as \test1.txt

@josesimoes
Copy link
Member

The code for STM32 is already taking care of this.

The test code above runs just fine on STM32F769I-DISCO loaded with an SD Card.

@josesimoes josesimoes merged commit a44e434 into nanoframework:develop May 27, 2019
@AdrianSoundy AdrianSoundy deleted the storage_rename branch May 29, 2019 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Series: ESP32 Everything related specifically with ESP32 series targets Type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants