replaceSymlink(): Handle the case where the temporary file already exists
Not really necessary anymore for #849, but still nice to have.
This commit is contained in:
		
							parent
							
								
									8e8caf7f3e
								
							
						
					
					
						commit
						2965d40612
					
				
					 1 changed files with 13 additions and 4 deletions
				
			
		|  | @ -496,12 +496,21 @@ void createSymlink(const Path & target, const Path & link) | |||
| 
 | ||||
| void replaceSymlink(const Path & target, const Path & link) | ||||
| { | ||||
|     Path tmp = canonPath(dirOf(link) + "/.new_" + baseNameOf(link)); | ||||
|     for (unsigned int n = 0; true; n++) { | ||||
|         Path tmp = canonPath(fmt("%s/.%d_%s", dirOf(link), n, baseNameOf(link))); | ||||
| 
 | ||||
|         try { | ||||
|             createSymlink(target, tmp); | ||||
|         } catch (SysError & e) { | ||||
|             if (e.errNo == EEXIST) continue; | ||||
|             throw; | ||||
|         } | ||||
| 
 | ||||
|         if (rename(tmp.c_str(), link.c_str()) != 0) | ||||
|             throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % link); | ||||
| 
 | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue