rename_variation3.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Test rename() function: usage variations-4
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip.. only for Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. $file_path = dirname(__FILE__);
  12. $dest_dir = "$file_path/rename_variation3_dir";
  13. // create the $dest_dir
  14. mkdir($dest_dir);
  15. echo "\n*** Testing rename() on hard links ***\n";
  16. $filename = $file_path."/rename_variation31.tmp";
  17. @unlink($filename);
  18. var_dump(touch($filename));
  19. $linkname = $file_path."/rename_variation3_hard_link1.tmp";
  20. var_dump(link($filename, $linkname));
  21. //rename the link to a new name in the same dir
  22. $dest_linkname = $file_path."/rename_variation3_hard_link2.tmp";
  23. var_dump( rename( $filename, $dest_linkname) );
  24. //ensure that link was renamed
  25. var_dump( file_exists($filename) ); // expecting false
  26. var_dump( file_exists($dest_linkname) ); // expecting true
  27. // rename a hard link across dir
  28. var_dump( rename($dest_linkname, $dest_dir."/rename_variation3_hard_link2.tmp") );
  29. //ensure that link got renamed
  30. var_dump( file_exists($dest_linkname) ); // expecting false
  31. var_dump( file_exists($dest_dir."/rename_variation3_hard_link2.tmp") ); // expecting true
  32. // delete the link file now
  33. unlink($dest_dir."/rename_variation3_hard_link2.tmp");
  34. echo "Done\n";
  35. ?>
  36. --CLEAN--
  37. <?php
  38. $file_path = dirname(__FILE__);
  39. unlink($file_path."/rename_variation3_hard_link1.tmp");
  40. rmdir($file_path."/rename_variation3_dir");
  41. ?>
  42. --EXPECTF--
  43. *** Testing rename() on hard links ***
  44. bool(true)
  45. bool(true)
  46. bool(true)
  47. bool(false)
  48. bool(true)
  49. bool(true)
  50. bool(false)
  51. bool(true)
  52. Done