]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/referencecache.cpp
Merge commit 'a764616a9c1b2f9148e3381f808b600c512592c9' into master-merge
[xonotic/netradiant.git] / radiant / referencecache.cpp
index 9ceeba1bc78fe0e0578d2d3ec97dca2459afa951..88f3fb3afbe0b4ac3f7375a76eeb068087ae9395 100644 (file)
@@ -124,8 +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";
@@ -137,7 +143,27 @@ 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. */
+               bool make_backup;
+               struct stat st;
+               if ( lstat(fullpath.c_str(), &st) == 0 ) {
+                       make_backup = true;             // file exists
+                       if ( (st.st_mode & S_IFMT) == S_IFLNK ) {
+                               make_backup = false;    // .. but it is a symlink
+                       }
+               } else {
+                       make_backup = false;            // nothing to move
+               }
+
+               if ( !make_backup || file_saveBackup( fullpath.c_str() ) ) {
+#endif
                        return MapResource_saveFile( format, root, Map_Traverse, fullpath.c_str() );
                }