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

FileStation().Rename().RenameAync() only works when there is one item to rename and brackets removed from URL #126

Open
lyellick opened this issue Jun 22, 2020 · 0 comments

Comments

@lyellick
Copy link

While debugging the RenameAsync extension sending the RenameParamters it would only rename a file/directory if I caught the 'rename' method and removed any brackets in the URL. When testing with multiple files/directories to rename I would get the 408 error (No such file or directory).

To add there seems to be an additional issue when you do not set a additional parameter. The below work around removes a zero addition parameter if there are no additional parameters.

Note: The share name is a guid. Couldn't think of a name for testing and is not a weird glitch.

Directory Tree for '/8c47db36-cce9-4fff-b4b2-a5df3a6a' share:

  • recycle
  • Folder A
    • example.txt
  • example.txt

Workaround:

SynologyConnectionExtension.cs: Line 108

Addition starting after line 110:

if (method.Equals("rename"))
                url = url.Replace("&additional=[0]", "").Replace("[", "").Replace("]", "");

GenericGetDataFromApiAsync var json raw output when trying multiple paths with workaround:

URL:

entry.cgi?path=/8c47db36-cce9-4fff-b4b2-a5df3a6a/example.txt,/8c47db36-cce9-4fff-b4b2-a5df3a6a/Folder A&name=test.txt,Folder B&additional=real_path&_sid=<MySID>&api=SYNO.FileStation.Rename&version=2&method=rename

Output:

{
    "error": {
        "code": 1200,
        "errors": [
            {
                "code": 408,
                "path": "/8c47db36-cce9-4fff-b4b2-a5df3a6a/example.txt,/8c47db36-cce9-4fff-b4b2-a5df3a6a/Folder A"
            }
        ]
    },
    "success": false
}

Code Executing RenameAsync(<RenameParamters>):

[HttpPost]
[Route("Rename")]
public async Task<IActionResult> Rename([FromBody] RenameParameters parameters)
{
    ResultData<RenameResult.IFileResult> renamed = new ResultData<RenameResult.IFileResult>();

    if (parameters.Path != null && parameters.Name != null)
    {
        if (parameters.Additional == 0)
            parameters.Additional = RenameAdditional.RealPath;

        using (var syno = _serviceProvider.GetService<ISynologyConnection>())
        {

            var login = await syno.Api().Auth().LoginAsync();

            renamed = await syno.FileStation().Rename().RenameAsync(parameters);

            var logout = await syno.Api().Auth().LogoutAsync();
        }
    }

    return Json(renamed);
}

Closing:

This is an awesome code base for working with the Synology api! Been learning A TON just looking through the code. I hope the above reproduction and workaround is helpful to fix/help me. I tried figuring out how to fix this and do a pull request, but to be honest the code base is more sophisticated than I am capable of. The workaround is all I could come up with.

Thanks,

-- Lincoln

@lyellick lyellick changed the title FileStation().Rename().RenameAync() only works with there is one item to rename and brackets removed from URL FileStation().Rename().RenameAync() only works when there is one item to rename and brackets removed from URL Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant