Skip to content

Commit ff39347

Browse files
committed
fix
1 parent 6611623 commit ff39347

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/docs-mover/Move.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ await ProcessMarkdownFile(
8888
ChangeFormatString,
8989
oldLink,
9090
newLink,
91-
sourceFile,
91+
sourceFile == sourceMarkdownFile.SourceFile.FullName && !isDryRun ? targetPath : sourceFile,
9292
lineNumber,
9393
columnNumber
9494
));
@@ -97,19 +97,21 @@ await ProcessMarkdownFile(
9797
if (isDryRun)
9898
return 0;
9999

100-
var targetDirectory = Path.GetDirectoryName(targetPath);
101-
readFileSystem.Directory.CreateDirectory(targetDirectory!);
102-
readFileSystem.File.Move(sourcePath, targetPath);
100+
103101
try
104102
{
105103
foreach (var (filePath, _, newContent) in _changes)
106104
await writeFileSystem.File.WriteAllTextAsync(filePath, newContent, ctx);
105+
var targetDirectory = Path.GetDirectoryName(targetPath);
106+
readFileSystem.Directory.CreateDirectory(targetDirectory!);
107+
readFileSystem.File.Move(sourcePath, targetPath);
107108
}
108109
catch (Exception)
109110
{
110111
foreach (var (filePath, originalContent, _) in _changes)
111112
await writeFileSystem.File.WriteAllTextAsync(filePath, originalContent, ctx);
112113
writeFileSystem.File.Move(targetPath, sourcePath);
114+
_logger.LogError("An error occurred while moving files. Reverting changes");
113115
throw;
114116
}
115117
return 0;

0 commit comments

Comments
 (0)