Annotation of embedaddon/php/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation4.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 hard link
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 4 : Create file and a hard link to the file
25: Access data of the file through the hard link
26: Update the file through hard link
27: Check size of file and hard link
28: */
29: $file_path = dirname(__FILE__);
30:
31: echo "*** Accessing and updating data of file through hard link ***\n";
32: // Creating file and inserting data into it
33: $filename = "$file_path/symlink__link_linkinfo_is_link_variation4.tmp";
34: // create temp file
35: $file = fopen($filename, "w");
36: // fill data into file
37: fwrite($file, str_repeat("text", 20) );
38: fclose($file);
39:
40: echo "\n-- Access data of the file through the hard link --\n";
41: // create hard link to file
42: $linkname = "$file_path/symlink_link_linkinfo_is_link_link_variation4.tmp";
43: var_dump( link($filename, $linkname) );
44: $data_from_link = file_get_contents($linkname); // data read from $filename
45: var_dump( $data_from_link );
46:
47: echo "\n-- Check size of hard link and file --\n";
48: if( filesize($filename) == filesize($linkname) )
49: echo "\nSize of file and hard link are same\n";
50: else
51: echo "\nWarning: Size of file and hard link differ\n";
52:
53: echo "\n-- Updating file with data through hard link --\n";
54: // append link with data
55: $fp = fopen($linkname, "a"); // open in append mode
56: fwrite($fp, "Hello World");
57: fclose($fp);
58:
59: // now check temp file for data; it should append "Hello World"
60: $data_from_file = file_get_contents($filename);
61: var_dump( $data_from_file );
62:
63: echo "\n-- Check size of hard link and file --\n";
64: if( filesize($filename) == filesize($linkname) )
65: echo "\nSize of file and hard link are same\n";
66: else
67: echo "\nWarning: Size of file and hard link differ\n";
68:
69: echo "\n-- Updating file with data and check data through hard link --\n";
70: // write to temp file
71: $file = fopen($filename, "w");
72: fwrite($file, "Hello World");
73: fclose($file);
74:
75: // now check link for data; it should echo "Hello World"
76: $data_from_link = file_get_contents($linkname);
77: var_dump( $data_from_link );
78:
79: echo "\n-- Check size of hard link and file --\n";
80: var_dump( filesize($filename) );
81: var_dump( filesize($linkname) );
82: if( filesize($filename) == filesize($linkname) )
83: echo "\nSize of file and hard link are same\n";
84: else
85: echo "\nWarning: Size of file and hard link differ\n";
86:
87: // delete the link
88: unlink($linkname);
89: // delete the temporary file
90: unlink($filename);
91:
92: echo "Done\n";
93: ?>
94: --EXPECTF--
95: *** Accessing and updating data of file through hard link ***
96:
97: -- Access data of the file through the hard link --
98: bool(true)
99: string(80) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext"
100:
101: -- Check size of hard link and file --
102:
103: Size of file and hard link are same
104:
105: -- Updating file with data through hard link --
106: string(91) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttextHello World"
107:
108: -- Check size of hard link and file --
109:
110: Size of file and hard link are same
111:
112: -- Updating file with data and check data through hard link --
113: string(11) "Hello World"
114:
115: -- Check size of hard link and file --
116: int(11)
117: int(11)
118:
119: Size of file and hard link are same
120: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>