Overview
Comment:realpath doesn't work with non-existing files, make it a bit clever
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: cfa99e898d23ca28c9c320fb49a646e676e6e775687666afab5cee5d11e4da12
User & Date: bohwaz on 2021-03-15 19:38:12
Other Links: branch diff | manifest | tags
Context
2021-03-15
19:38
Make it a bit simpler in Config: only store and return a file location, not an object check-in: 06e529e9b2 user: bohwaz tags: dev
19:38
realpath doesn't work with non-existing files, make it a bit clever check-in: cfa99e898d user: bohwaz tags: dev
17:43
Fix attachements and page preview check-in: 3b40c56acd user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Files/Storage/FileSystem.php from [e562d716b9] to [8f61a9a210].

83
84
85
86
87
88
89
90










91
92
93
94
95
96
97
	static public function mkdir(File $file): bool
	{
		return Utils::safe_mkdir(self::getFullPath($file));
	}

	static protected function _getRealPath(string $path): ?string
	{
		return realpath(self::_getRoot() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path)) ?: null;










	}

	static public function getFullPath(File $file): ?string
	{
		return self::_getRealPath($file->path);
	}








|
>
>
>
>
>
>
>
>
>
>







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
	static public function mkdir(File $file): bool
	{
		return Utils::safe_mkdir(self::getFullPath($file));
	}

	static protected function _getRealPath(string $path): ?string
	{
		$path = self::_getRoot() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);

		$parts = explode(DIRECTORY_SEPARATOR, $path);

		foreach ($parts as $part) {
			if (substr($part, 0, 1) === '.') {
				return null;
			}
		}

		return $path;
	}

	static public function getFullPath(File $file): ?string
	{
		return self::_getRealPath($file->path);
	}

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	{
		$path = self::getFullPath($file);

		if (is_dir($path)) {
			return rmdir($path);
		}
		else {
			return unlink($path);
		}
	}

	static public function move(File $file, string $new_path): bool
	{
		$source = self::getFullPath($file);
		$target = self::_getRealPath($new_path);







|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	{
		$path = self::getFullPath($file);

		if (is_dir($path)) {
			return rmdir($path);
		}
		else {
			return Utils::safe_unlink($path);
		}
	}

	static public function move(File $file, string $new_path): bool
	{
		$source = self::getFullPath($file);
		$target = self::_getRealPath($new_path);
263
264
265
266
267
268
269

270
271
272
273
274
275
276

	static public function update(File $file): ?File
	{
		$path = self::getFullPath($file);

		// File has disappeared
		if (!file_exists($path)) {

			return null;
		}

		$type = is_dir($path) ? File::TYPE_DIRECTORY : File::TYPE_FILE;

		// Directories don't have a modified time here
		if ($type == File::TYPE_DIRECTORY && $file->type == File::TYPE_DIRECTORY) {







>







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

	static public function update(File $file): ?File
	{
		$path = self::getFullPath($file);

		// File has disappeared
		if (!file_exists($path)) {
			$file->delete();
			return null;
		}

		$type = is_dir($path) ? File::TYPE_DIRECTORY : File::TYPE_FILE;

		// Directories don't have a modified time here
		if ($type == File::TYPE_DIRECTORY && $file->type == File::TYPE_DIRECTORY) {