Annotation of embedaddon/php/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation3.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test symlink(), linkinfo(), link() and is_link() functions : usage variations - access/update file through softlink
                      3: --SKIPIF--
                      4: <?php
                      5: if (substr(PHP_OS, 0, 3) == 'WIN') {
                      6:     die('skip no symlinks on Windows');
                      7: }
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11: /* Prototype: bool symlink ( string $target, string $link );
                     12:    Description: creates a symbolic link to the existing target with the specified name link
                     13: 
                     14:    Prototype: bool is_link ( string $filename );
                     15:    Description: Tells whether the given file is a symbolic link.
                     16: 
                     17:    Prototype: bool link ( string $target, string $link );
                     18:    Description: Create a hard link
                     19: 
                     20:    Prototype: int linkinfo ( string $path );
                     21:    Description: Gets information about a link
                     22: */
                     23: 
                     24: /* Variation 3 : Create file and a soft link to the file
                     25:                  Access data of the file through the soft link 
                     26:                  Update the file through soft link
                     27:                  Check size of file and soft link link
                     28: */
                     29: 
                     30: $file_path = dirname(__FILE__);
                     31: echo "*** Accessing and updating data of file through soft link ***\n";
                     32: // Creating file and inserting data into it
                     33: $filename = "$file_path/symlink_link_linkinfo_is_link_variation3.tmp";
                     34: 
                     35: // create temp file
                     36: $file = fopen($filename, "w");
                     37: 
                     38: // create soft link to file
                     39: $linkname = "$file_path/symlink_link_linkinfo_is_link_link_variation3.tmp";
                     40: var_dump( symlink($filename, $linkname) );
                     41: // storing size of symlink in a local variable
                     42: $link_stat = lstat($linkname);  // lstat of link
                     43: $link_size = $link_stat[7];  // size of soft link
                     44: 
                     45: // fill data into file
                     46: fwrite($file, str_repeat("text", 20) );
                     47: fclose($file);
                     48: 
                     49: echo "\n-- Access data of the file through the soft link --\n";
                     50: $data_from_link = file_get_contents($linkname);  // data read from $filename
                     51: var_dump( $data_from_link );
                     52: 
                     53: echo "\n-- Check size of soft link and file --\n";
                     54: var_dump( filesize($filename) );
                     55: var_dump( filesize($linkname) );
                     56: 
                     57: // taking lstat of symlink
                     58: $stat = lstat($linkname);
                     59: // checking that size of symlink remains same
                     60: if ($link_size == $stat[7])
                     61:   echo "\nSoft link size remains same \n";
                     62: else
                     63:   echo "\nWarning: Soft link size has changed \n";
                     64: 
                     65: echo "\n-- Updating file with data through soft link --\n";
                     66: // append link with data
                     67: $fp = fopen($linkname, "a");  // open in append mode
                     68: fwrite($fp, "Hello World");
                     69: fclose($fp);
                     70: 
                     71: // now check temp file for data; it should append "Hello World"
                     72: $data_from_file = file_get_contents($filename);
                     73: var_dump( $data_from_file );
                     74: 
                     75: echo "\n-- Check size of soft link and file --\n";
                     76: var_dump( filesize($filename) );
                     77: var_dump( filesize($linkname) );
                     78: 
                     79: // taking lstat of symlink
                     80: $stat = lstat($linkname);
                     81: // checking that size of symlink remains same
                     82: if ($link_size == $stat[7])
                     83:   echo "\nSoft link size remains same \n";
                     84: else
                     85:   echo "\nWarning: Soft link size has changed \n";
                     86: 
                     87: echo "\n-- Updating file with data and check data through soft link --\n";
                     88: // write to temp file
                     89: $file = fopen($filename, "w");
                     90: fwrite($file, "Hello World");
                     91: fclose($file);
                     92: 
                     93: // now check link for data; it should echo "Hello World"
                     94: $data_from_link = file_get_contents($linkname);
                     95: var_dump( $data_from_link );
                     96: 
                     97: echo "\n-- Check size of soft link and file --\n";
                     98: var_dump( filesize($filename) );
                     99: var_dump( filesize($linkname) );
                    100: 
                    101: // taking lstat of symlink
                    102: $stat = lstat($linkname);
                    103: // checking that size of symlink remains same
                    104: if ($link_size == $stat[7])
                    105:   echo "\nSoft link size remains same \n";
                    106: else
                    107:   echo "\nWarning: Soft link size has changed \n";
                    108: 
                    109: // delete the link
                    110: unlink($linkname);
                    111: // delete the temporary file
                    112: unlink($filename);
                    113: 
                    114: echo "Done\n";
                    115: ?>
                    116: --EXPECTF--
                    117: *** Accessing and updating data of file through soft link ***
                    118: bool(true)
                    119: 
                    120: -- Access data of the file through the soft link --
                    121: string(80) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext"
                    122: 
                    123: -- Check size of soft link and file --
                    124: int(80)
                    125: int(80)
                    126: 
                    127: Soft link size remains same 
                    128: 
                    129: -- Updating file with data through soft link --
                    130: string(91) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttextHello World"
                    131: 
                    132: -- Check size of soft link and file --
                    133: int(91)
                    134: int(91)
                    135: 
                    136: Soft link size remains same 
                    137: 
                    138: -- Updating file with data and check data through soft link --
                    139: string(11) "Hello World"
                    140: 
                    141: -- Check size of soft link and file --
                    142: int(11)
                    143: int(11)
                    144: 
                    145: Soft link size remains same 
                    146: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>