File: fs_win32.php

package info (click to toggle)
gallery 1.5-1sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 21,172 kB
  • ctags: 4,516
  • sloc: php: 26,456; sh: 427; perl: 188; makefile: 58; xml: 48
file content (205 lines) | stat: -rw-r--r-- 5,041 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2005 Bharat Mediratta
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: fs_win32.php,v 1.27.2.2 2005/04/14 01:48:31 cryptographite Exp $
 */
?>
<?php
function fs_copy($source, $dest) {
	$umask = umask(0133);
	$results = copy(
		fs_import_filename($source, 0), 
		fs_import_filename($dest, 0));
	umask($umask);
}

function fs_file_exists($filename) {
	$filename = fs_import_filename($filename, 0);
	debug("Checking for [$filename] == " . @file_exists($filename));
	return @file_exists($filename);
}

function fs_is_link($filename) {
	$filename = fs_import_filename($filename, 0);
	return is_link($filename);
}

function fs_filesize($filename) {
	$filename = fs_import_filename($filename, 0);
	return filesize($filename);
}

function fs_fopen($filename, $mode, $use_include_path=0) {
	$filename = fs_import_filename($filename, 0);
	return fopen($filename, $mode, $use_include_path);
}

function fs_file_get_contents($filename) {
	$filename = fs_import_filename($filename, 0);

	if (function_exists("file_get_contents")) {
		$tmp = @file_get_contents($filename);
	} else {
		if ($fd = fs_fopen($fname, "rb")) {
			while (!feof($fd)) {
				$tmp .= fread($fd, 65536);
			}
			fclose($fd);
		}
	}
	return $tmp;
}

function fs_is_dir($filename) {
	$filename = fs_import_filename($filename, 0);
	return @is_dir($filename);
}

function fs_is_file($filename) {
	$filename = fs_import_filename($filename, 0);
	return @is_file($filename);
}

function fs_is_readable($filename) {
	$filename = fs_import_filename($filename, 0);
	return @is_readable($filename);
}


function fs_opendir($path) {
	$path = fs_import_filename($path, 0);
	return opendir($path);
}

function fs_rename($oldname, $newname) {
	$oldname = fs_import_filename($oldname, 0);
	$newname = fs_import_filename($newname, 0);

	/* 
	 * It appears that win32 doesn't like it when you rename 
	 * a file to end with ".dat.bak".  Why?  This is very 
	 * annoying.
	 */
	$newname = str_replace(".dat.bak", ".bak", $newname);

	debug("Rename $oldname -> $newname");
	clearstatcache();
	if (file_exists("$newname.bak")) {
		unlink("$newname.bak");
	}
	if (file_exists("$newname")) {
		return rename($newname, "$newname.bak") &&
			rename($oldname, $newname);
	} else {
		return rename($oldname, $newname);
	}
}

function fs_stat($filename) {
	$filename = fs_import_filename($filename, 0);
	return stat($filename);
}

/* This function deletes a file.
** The errormessage is surpressed !
*/
function fs_unlink($filename) {
	$filename = fs_import_filename($filename, 0);
	return @unlink($filename);
}

function fs_executable($filename) {
	$filename = fs_import_filename($filename, 0);
	if (!strstr($filename, ".exe")) {
		$filename .= ".exe";
	}
	return $filename;
}

function fs_mkdir($filename, $perms) {
	$umask = umask(0);
	$results = mkdir(fs_import_filename($filename, 0), $perms);
	umask($umask);
	return $results;
}

function fs_import_filename($filename, $for_exec=1) {
	debug("Import before: $filename");
	# Change / and : to \ and ;
	#
 	$filename = str_replace("/", "\\", $filename);
 	$filename = str_replace(":", ";", $filename);

	# Change D;\apps to D:\apps (the : got mangled by the above
	# transform).
	#
	if ($filename{1} == ';') {
		$filename{1} = ':';
	}

	# Convert "D\whoami" to "D:\whoami"
	#
	$filename = ereg_replace("^([A-Z])\\\\(.*)", "\\1:\\\\2", $filename);

	# Convert "\Perl\bin\;D/whoami" to "D:\Perl\bin\whoami"
	#
	$filename = ereg_replace("(.*);([A-Z])\\\\(.*)", "\\2:\\1\\3", $filename);

	if ($for_exec) {
		if (strstr($filename, " ")) {
			$filename = "\"$filename\"";
		}
	}	

	debug("Import after: $filename");
	return $filename;
}

function fs_export_filename($filename) {
	
	# Convert "d:\winnt\temp" to "d:/winnt/temp"
	#
	while (strstr($filename, "\\\\")) {
		$filename = str_replace("\\\\", "\\", $filename);
	}
	$filename = str_replace("\\", "/", $filename);

	return $filename;
}

function fs_exec($cmd, &$results, &$status, $debugfile) {

	// We can't redirect stderr with Windows.  Hope that we won't need to.
	return exec($cmd, $results, $status);
}

function fs_tempdir() {
	return export_filename($gallery->app->tmpDir); 
}

function fs_is_executable($filename) {
	return eregi(".(exe|com|vbs)$", $filename);
}

function debug($msg) {
	if (0) {
		print "<br>$msg<br>";
	}
}
?>