" " "", tmp. , , :
mkdir -p tmp/real_dir1 tmp/real_dir2
touch tmp/real_dir1/a tmp/real_dir2/a
ln -s tmp/real_dir1 target_dir
ln -sf tmp/real_dir2 tmp/target_dir
mv tmp/target_dir ./
An example here is taken from: http://axialcorps.wordpress.com/2013/07/03/atomically-replacing-files-and-directories/
It comes down to (in pseudo-code):
mkdir('./tmp');
mkdir('./tmp/real_dir1');
mkdir('./tmp/real_dir2');
symlink('./tmp/real_dir1', './target_dir')
symlink('./tmp/real_dir2', './tmp/target_dir')
rename('./tmp/target_dir', './target_dir')
The final renaming here is atomic, so the action will either succeed or fail completely, from the point of view of any process using the directory, the action is atomic.
source
share