Skip to content

File directory rename doesn't work when only changing character case #7

@davidnmbond

Description

@davidnmbond

File directory rename doesn't work when only changing character case. The issue is in FileSystemDriver.cs.

Fix is as follows:

JsonResult IDriver.Rename(string target, string name) { var fullPath = ParsePath(target); var answer = new ReplaceResponse(); answer.Removed.Add(target); RemoveThumbs(fullPath); if (fullPath.Directory != null) { var newPath = Path.Combine(fullPath.Directory.Parent.FullName, name); // Rename won't work if the case insensitive before/afters match, so must go via another name first. if (fullPath.Directory.FullName.ToLowerInvariant() == newPath.ToLowerInvariant()) { // Create a non-existing temp path string tempPath; var counter = 0; while (Directory.Exists(tempPath = newPath + counter++)) { } // Move to the temp path Directory.Move(fullPath.Directory.FullName, tempPath); // Move to the newPath Directory.Move(tempPath, newPath); } else { Directory.Move(fullPath.Directory.FullName, newPath); } answer.Added.Add(DtoBase.Create(new DirectoryInfo(newPath), fullPath.Root)); } else { var newPath = Path.Combine(fullPath.File.DirectoryName, name); File.Move(fullPath.File.FullName, newPath); answer.Added.Add(DtoBase.Create(new FileInfo(newPath), fullPath.Root)); } return Json(answer); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions