]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant: restore original backup behaviour on Windows, ref 4d38a666
authorThomas Debesse <dev@illwieckz.net>
Sun, 19 Jun 2022 19:17:32 +0000 (21:17 +0200)
committerThomas Debesse <dev@illwieckz.net>
Sun, 19 Jun 2022 19:17:32 +0000 (21:17 +0200)
Restore original backup behaviour on Windows as NT symlinks are not handled
yet, see 4d38a666f972e7cbc2156865a2c99ecf2192c467.

radiant/referencecache.cpp

index cf5abe0c928e3526af1c5eee979b8c42e0f94372..88f3fb3afbe0b4ac3f7375a76eeb068087ae9395 100644 (file)
@@ -124,7 +124,14 @@ bool file_saveBackup( const char* path ){
                StringOutputStream backup( 256 );
                backup << StringRange( path, path_get_extension( path ) ) << "bak";
 
+#if GDEF_OS_WINDOWS
+               // NT symlinks are not supported yet.
+               return ( !file_exists( backup.c_str() ) || file_remove( backup.c_str() ) ) // remove backup
+                          && file_move( path, backup.c_str() ); // rename current to backup
+#else
+               // POSIX symlinks are supported.
                return file_move( path, backup.c_str() ); // rename current to backup
+#endif
        }
 
        globalErrorStream() << "map path is not writeable: " << makeQuoted( path ) << "\n";
@@ -136,6 +143,11 @@ bool MapResource_save( const MapFormat& format, scene::Node& root, const char* p
        fullpath << path << name;
 
        if ( path_is_absolute( fullpath.c_str() ) ) {
+#if GDEF_OS_WINDOWS
+               // NT symlinks are not supported yet.
+               if ( !file_exists( fullpath.c_str() ) || file_saveBackup( fullpath.c_str() ) ) {
+#else
+               // POSIX symlinks are supported.
                /* We don't want a backup + rename operation if the .map file is
                 * a symlink. Otherwise we'll break the user's careful symlink setup.
                 * Just overwrite the original file. Assume the user has versioning. */
@@ -151,6 +163,7 @@ bool MapResource_save( const MapFormat& format, scene::Node& root, const char* p
                }
 
                if ( !make_backup || file_saveBackup( fullpath.c_str() ) ) {
+#endif
                        return MapResource_saveFile( format, root, Map_Traverse, fullpath.c_str() );
                }