@@ -104,6 +104,19 @@ fn do_move(
104
104
return Ok ( vec ! [ ] ) ;
105
105
}
106
106
107
+ let old_folder_path = slug_to_repo_folder_path ( real_old_slug, locale) ?;
108
+ let new_folder_path = slug_to_repo_folder_path ( new_slug, locale) ?;
109
+
110
+ if root_for_locale ( locale) ?
111
+ . join ( & new_folder_path)
112
+ . try_exists ( ) ?
113
+ {
114
+ return Err ( ToolError :: TargetDirExists (
115
+ new_folder_path,
116
+ new_slug. to_string ( ) ,
117
+ ) ) ;
118
+ }
119
+
107
120
let pairs = [ doc. clone ( ) ]
108
121
. iter ( )
109
122
. chain ( & subpages)
@@ -146,16 +159,6 @@ fn do_move(
146
159
// to a new location. This will move all children as well and
147
160
// makes sure that we get a proper "file moved" in the git history.
148
161
149
- let mut old_folder_path = PathBuf :: from ( locale. as_folder_str ( ) ) ;
150
- let url = build_url ( real_old_slug, locale, PageCategory :: Doc ) ?;
151
- let UrlMeta { folder_path, .. } = url_meta_from ( & url) ?;
152
- old_folder_path. push ( folder_path) ;
153
-
154
- let mut new_folder_path = PathBuf :: from ( locale. as_folder_str ( ) ) ;
155
- let url = build_url ( new_slug, locale, PageCategory :: Doc ) ?;
156
- let UrlMeta { folder_path, .. } = url_meta_from ( & url) ?;
157
- new_folder_path. push ( folder_path) ;
158
-
159
162
// Make sure the target parent directory exists.
160
163
if let Some ( target_parent_path) = new_folder_path. parent ( ) {
161
164
let absolute_target_parent_path = root_for_locale ( locale) ?. join ( target_parent_path) ;
@@ -219,6 +222,14 @@ fn do_move(
219
222
Ok ( pairs)
220
223
}
221
224
225
+ fn slug_to_repo_folder_path ( slug : & str , locale : Locale ) -> Result < PathBuf , ToolError > {
226
+ let mut new_folder_path = PathBuf :: from ( locale. as_folder_str ( ) ) ;
227
+ let url = build_url ( slug, locale, PageCategory :: Doc ) ?;
228
+ let UrlMeta { folder_path, .. } = url_meta_from ( & url) ?;
229
+ new_folder_path. push ( folder_path) ;
230
+ Ok ( new_folder_path)
231
+ }
232
+
222
233
fn validate_args ( old_slug : & str , new_slug : & str ) -> Result < ( ) , ToolError > {
223
234
if old_slug. is_empty ( ) {
224
235
return Err ( ToolError :: InvalidSlug ( Cow :: Borrowed (
0 commit comments