@@ -1221,43 +1221,6 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
12211221 linkloc = pstrdup (linkloc_with_version_dir );
12221222 get_parent_directory (linkloc );
12231223
1224- /* Remove the symlink target directory if it exists or is valid. */
1225- rllen = readlink (linkloc , link_target_dir , sizeof (link_target_dir ));
1226- if (rllen < 0 )
1227- {
1228- ereport (redo ? LOG : ERROR ,
1229- (errcode_for_file_access (),
1230- errmsg ("could not read symbolic link \"%s\": %m" ,
1231- linkloc )));
1232- }
1233- else if (rllen >= sizeof (link_target_dir ))
1234- {
1235- ereport (redo ? LOG : ERROR ,
1236- (errcode_for_file_access (),
1237- errmsg ("symbolic link \"%s\" target is too long" ,
1238- linkloc )));
1239- }
1240- else
1241- {
1242- link_target_dir [rllen ] = '\0' ;
1243- if (access (link_target_dir , F_OK ) != 0 )
1244- {
1245- ereport (redo ? LOG : ERROR ,
1246- (errcode_for_file_access (),
1247- errmsg ("could not open directory \"%s\": %m" ,
1248- link_target_dir )));
1249- }
1250- else
1251- {
1252- if (directory_is_empty (link_target_dir ) && rmdir (link_target_dir ) < 0 )
1253- ereport (redo ? LOG : ERROR ,
1254- (errcode_for_file_access (),
1255- errmsg ("could not remove directory \"%s\": %m" ,
1256- link_target_dir )));
1257- }
1258- }
1259-
1260-
12611224 if (lstat (linkloc , & st ) < 0 )
12621225 {
12631226 int saved_errno = errno ;
@@ -1281,6 +1244,42 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
12811244 }
12821245 else if (S_ISLNK (st .st_mode ))
12831246 {
1247+ /* Remove the symlink target directory if it exists or is valid. */
1248+ rllen = readlink (linkloc , link_target_dir , sizeof (link_target_dir ));
1249+ if (rllen < 0 )
1250+ {
1251+ ereport (redo ? LOG : ERROR ,
1252+ (errcode_for_file_access (),
1253+ errmsg ("could not read symbolic link \"%s\": %m" ,
1254+ linkloc )));
1255+ }
1256+ else if (rllen >= sizeof (link_target_dir ))
1257+ {
1258+ ereport (redo ? LOG : ERROR ,
1259+ (errcode_for_file_access (),
1260+ errmsg ("symbolic link \"%s\" target is too long" ,
1261+ linkloc )));
1262+ }
1263+ else
1264+ {
1265+ link_target_dir [rllen ] = '\0' ;
1266+ if (access (link_target_dir , F_OK ) != 0 )
1267+ {
1268+ ereport (redo ? LOG : ERROR ,
1269+ (errcode_for_file_access (),
1270+ errmsg ("could not open directory \"%s\": %m" ,
1271+ link_target_dir )));
1272+ }
1273+ else
1274+ {
1275+ if (directory_is_empty (link_target_dir ) && rmdir (link_target_dir ) < 0 )
1276+ ereport (redo ? LOG : ERROR ,
1277+ (errcode_for_file_access (),
1278+ errmsg ("could not remove directory \"%s\": %m" ,
1279+ link_target_dir )));
1280+ }
1281+ }
1282+
12841283 if (unlink (linkloc ) < 0 )
12851284 {
12861285 int saved_errno = errno ;
0 commit comments