Skip to content

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

Description

@lyellick

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

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