summaryrefslogtreecommitdiffstats
path: root/tests/014-stream.phpt
blob: 69b881edc7293f49fd93da40d5d2d51188fb4073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--TEST--
Check for stream
--SKIPIF--
<?php
if (!extension_loaded("rpminfo")) print "skip";
if (version_compare(RPMVERSION, '4.13', 'lt')) print("skip librpm is older than 4.13");
?>
--FILE--
<?php 
$d = "rpm://" . __DIR__ . "/bidon.rpm#/usr/share/doc/bidon";
$n = "rpm://" . __DIR__ . "/bidon.rpm#/usr/share/doc/bidon/README";
$x = "rpm://" . __DIR__ . "/bidon.rpm#/usr/share/doc/bidon/MISSING";
$foo = "rpm://" . __DIR__ . "/bidon.rpm#/etc/foo.conf";
$bar = "rpm://" . __DIR__ . "/bidon.rpm#/etc/bar.conf";
$toto = "rpm://" . __DIR__ . "/bidon.rpm#/etc/toto.conf";

echo "+ wrapper\n";
var_dump(in_array('rpm', stream_get_wrappers()));

echo "+ stat\n";
$s = stat($d); // S_ISDIR
var_dump($s['size'], $s['mode'] , ($s['mode'] & 0170000) == 0040000 ? "OK" : "KO");
var_dump(file_exists($d), is_dir($d), is_file($d), is_link($n));
$s = stat($n); // S_ISREG
var_dump($s['size'], $s['mode'] , ($s['mode'] & 0170000) == 0100000 ? "OK" : "KO");
var_dump(file_exists($n), is_dir($n), is_file($n), is_link($n));
$s = stat($toto); // S_ISLNK
var_dump($s['size'], $s['mode'] , ($s['mode'] & 0170000) == 0120000 ? "OK" : "KO");
var_dump(file_exists($toto), is_dir($toto), is_file($toto), is_link($toto));

echo "+ file\n";
var_dump($f = fopen($n, "r"));
$s = fstat($f);
var_dump($s['size'], $s['mode']);
var_dump(trim(fread($f, 10)));
var_dump(feof($f));
var_dump(trim(fread($f, 100)));
var_dump(feof($f));
fclose($f);

echo "+ stream\n";
var_dump(trim(file_get_contents($n)));		// Existing file
var_dump(trim(file_get_contents($foo)));	// Hardlink with content
var_dump(trim(file_get_contents($bar)));	// hardlink without content
var_dump(file_get_contents($x)); 		// Missing file

echo "+ symlink\n";
var_dump(rpmgetsymlink(__DIR__ . "/bidon.rpm", "missing"));
var_dump(rpmgetsymlink(__DIR__ . "/bidon.rpm", "/etc/foo.conf"));  // not a symlink
var_dump(rpmgetsymlink(__DIR__ . "/bidon.rpm", "/etc/toto.conf")); // symlink
?>
Done
--EXPECTF--
+ wrapper
bool(true)
+ stat
int(0)
int(16877)
string(2) "OK"
bool(true)
bool(true)
bool(false)
bool(false)
int(30)
int(33188)
string(2) "OK"
bool(true)
bool(false)
bool(true)
bool(false)
int(8)
int(41471)
string(2) "OK"
bool(true)
bool(false)
bool(false)
bool(true)
+ file
resource(%d) of type (stream)
int(30)
int(33188)
string(10) "Thu Oct 19"
bool(false)
string(18) "12:01:02 CEST 2023"
bool(true)
+ stream
string(29) "Thu Oct 19 12:01:02 CEST 2023"
string(7) "content"
string(7) "content"

Warning: file_get_contents(%s/bidon.rpm#/usr/share/doc/bidon/MISSING): Failed to open stream: operation failed in %s on line %d
bool(false)
+ symlink
NULL
string(0) ""
string(8) "foo.conf"
Done