summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.packaging/org.eclipse.jgit.target
Commit message (Expand)AuthorAgeFilesLines
* Merge branch 'stable-6.0'Matthias Sohn2021-12-046-6/+6
|\
| * Merge branch 'stable-5.13' into stable-6.0Matthias Sohn2021-12-046-6/+6
| |\
| | * Merge branch 'stable-5.12' into stable-5.13Matthias Sohn2021-12-0418-16/+18
| | |\
| | | * Merge branch 'stable-5.11' into stable-5.12Matthias Sohn2021-12-0417-15/+17
| | | |\
| | | | * Merge branch 'stable-5.10' into stable-5.11Matthias Sohn2021-12-0416-14/+16
| | | | |\
| | | | | * Merge branch 'stable-5.9' into stable-5.10Matthias Sohn2021-12-0415-13/+15
| | | | | |\
| | | | | | * Merge branch 'stable-5.8' into stable-5.9Matthias Sohn2021-12-0414-12/+14
| | | | | | |\
| | | | | | | * Merge branch 'stable-5.7' into stable-5.8Matthias Sohn2021-12-0415-27/+29
| | | | | | | |\
| | | | | | | | * Merge branch 'stable-5.6' into stable-5.7Matthias Sohn2021-12-0422-49/+51
| | | | | | | | |\
| | | | | | | | | * Merge branch 'stable-5.5' into stable-5.6Matthias Sohn2021-12-0420-44/+45
| | | | | | | | | |\
| | | | | | | | | | * Merge branch 'stable-5.4' into stable-5.5Matthias Sohn2021-12-0418-40/+41
| | | | | | | | | | |\
| | | | | | | | | | | * Merge branch 'stable-5.3' into stable-5.4Matthias Sohn2021-12-0416-36/+37
| | | | | | | | | | | |\
| | | | | | | | | | | | * Merge branch 'stable-5.2' into stable-5.3Matthias Sohn2021-12-0414-32/+33
| | | | | | | | | | | | |\
| | | | | | | | | | | | | * Merge branch 'stable-5.1' into stable-5.2Matthias Sohn2021-12-049-17/+17
| | | | | | | | | | | | | |\
| | | | | | | | | | | | | | * Fix p2 repository URLsMatthias Sohn2021-12-028-20/+20
| | | | | | | | | | | | | | * Prepare 5.1.17-SNAPSHOT buildsMatthias Sohn2021-06-052-2/+2
| | | | | | | | | | | | | | * JGit v5.1.16.202106041830-rv5.1.16.202106041830-rMatthias Sohn2021-06-052-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.16-SNAPSHOT buildsMatthias Sohn2020-12-022-2/+2
| | | | | | | | | | | | | | * JGit v5.1.15.202012011955-rv5.1.15.202012011955-rMatthias Sohn2020-12-022-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.15-SNAPSHOT buildsMatthias Sohn2020-11-262-2/+2
| | | | | | | | | | | | | | * JGit v5.1.14.202011251942-rv5.1.14.202011251942-rMatthias Sohn2020-11-262-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.14-SNAPSHOT buildsMatthias Sohn2020-02-112-2/+2
| | | | | | | | | | | | | | * JGit v5.1.13.202002110435-rv5.1.13.202002110435-rMatthias Sohn2020-02-112-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.13-SNAPSHOT buildsMatthias Sohn2019-10-022-2/+2
| | | | | | | | | | | | | | * JGit v5.1.12.201910011832-rv5.1.12.201910011832-rMatthias Sohn2019-10-022-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.12-SNAPSHOT buildsMatthias Sohn2019-09-032-2/+2
| | | | | | | | | | | | | | * JGit v5.1.11.201909031202-rv5.1.11.201909031202-rMatthias Sohn2019-09-032-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.11-SNAPSHOT buildsMatthias Sohn2019-08-232-2/+2
| | | | | | | | | | | | | | * JGit v5.1.10.201908230655-rv5.1.10.201908230655-rMatthias Sohn2019-08-232-2/+2
| | | | | | | | | | | | | | * Prepare 5.1.10-SNAPSHOT buildsMatthias Sohn2019-08-212-2/+2
| | | | | | | | | | | | | | * JGit v5.1.9.201908210455-rv5.1.9.201908210455-rMatthias Sohn2019-08-212-2/+2
| | | | | | | | | | | | * | | Prepare 5.3.10-SNAPSHOT buildsMatthias Sohn2020-12-022-2/+2
| | | | | | | | | | | | * | | JGit v5.3.9.202012012026-rv5.3.9.202012012026-rMatthias Sohn2020-12-022-2/+2
| | | | | | | | | | | | * | | Prepare 5.3.9-SNAPSHOT buildsMatthias Sohn2020-11-262-2/+2
| | | | | | | | | | | | * | | JGit v5.3.8.202011260953-rv5.3.8.202011260953-rMatthias Sohn2020-11-262-2/+2
| | | | | | | | | | | | * | | Prepare 5.3.8-SNAPSHOT buildsMatthias Sohn2020-02-112-2/+2
| | | | | | | | | | | | * | | JGit v5.3.7.202002110540-rv5.3.7.202002110540-rMatthias Sohn2020-02-112-2/+2
| | | | | | | | | | | | * | | Prepare 5.3.7-SNAPSHOT buildsMatthias Sohn2019-10-022-2/+2
| | | | | | | | | | | | * | | JGit v5.3.6.201910020505-rv5.3.6.201910020505-rMatthias Sohn2019-10-022-2/+2
| | | | | | | | | | | | * | | Prepare 5.3.6-SNAPSHOT buildsMatthias Sohn2019-09-042-2/+2
| | | | | | | | | | | | * | | JGit v5.3.5.201909031855-rv5.3.5.201909031855-rMatthias Sohn2019-09-042-2/+2
| | | | | | | | | | | * | | | Prepare 5.4.4-SNAPSHOT buildsMatthias Sohn2019-09-042-2/+2
| | | | | | | | | | | * | | | JGit v5.4.3.201909031940-rv5.4.3.201909031940-rMatthias Sohn2019-09-042-2/+2
| | | | | | | | | | * | | | | Prepare 5.5.2-SNAPSHOT buildsMatthias Sohn2019-10-032-2/+2
| | | | | | | | | | * | | | | JGit v5.5.1.201910021850-rv5.5.1.201910021850-rMatthias Sohn2019-10-032-2/+2
| | | | | | | | | | * | | | | Prepare 5.5.1-SNAPSHOT buildsMatthias Sohn2019-09-112-2/+2
| | | | | | | | | | * | | | | JGit v5.5.0.201909110433-rv5.5.0.201909110433-rMatthias Sohn2019-09-112-2/+2
| | | | | | | | | * | | | | | Prepare 5.6.2-SNAPSHOT buildsMatthias Sohn2020-02-142-2/+2
| | | | | | | | | * | | | | | JGit v5.6.1.202002131546-rv5.6.1.202002131546-rMatthias Sohn2020-02-132-2/+2
| | | | | | | | | * | | | | | Prepare 5.6.1-SNAPSHOT buildsMatthias Sohn2019-12-112-2/+2
kport/49176/stable30 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Stream/Quota.php
blob: 8d27575c5689a049f6b12a3aed06ba64af9f2c83 (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
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
<?php
/**
 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Robin Appelman <icewind@owncloud.com>
 * @author Vincent Petry <pvince81@owncloud.com>
 *
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OC\Files\Stream;

/**
 * stream wrapper limits the amount of data that can be written to a stream
 *
 * usage: void \OC\Files\Stream\Quota::register($id, $stream, $limit)
 * or:    resource \OC\Files\Stream\Quota::wrap($stream, $limit)
 */
class Quota {
	private static $streams = array();

	/**
	 * @var resource $source
	 */
	private $source;

	/**
	 * @var int $limit
	 */
	private $limit;

	/**
	 * @param string $id
	 * @param resource $stream
	 * @param int $limit
	 */
	public static function register($id, $stream, $limit) {
		self::$streams[$id] = array($stream, $limit);
	}

	/**
	 * remove all registered streams
	 */
	public static function clear() {
		self::$streams = array();
	}

	/**
	 * @param resource $stream
	 * @param int $limit
	 * @return resource
	 */
	static public function wrap($stream, $limit) {
		$id = uniqid();
		self::register($id, $stream, $limit);
		$meta = stream_get_meta_data($stream);
		return fopen('quota://' . $id, $meta['mode']);
	}

	public function stream_open($path, $mode, $options, &$opened_path) {
		$id = substr($path, strlen('quota://'));
		if (isset(self::$streams[$id])) {
			list($this->source, $this->limit) = self::$streams[$id];
			return true;
		} else {
			return false;
		}
	}

	public function stream_seek($offset, $whence = SEEK_SET) {
		if ($whence === SEEK_END){
			// go to the end to find out last position's offset
			$oldOffset = $this->stream_tell();
			if (fseek($this->source, 0, $whence) !== 0){
				return false;
			}
			$whence = SEEK_SET;
			$offset = $this->stream_tell() + $offset;
			$this->limit += $oldOffset - $offset;
		}
		else if ($whence === SEEK_SET) {
			$this->limit += $this->stream_tell() - $offset;
		} else {
			$this->limit -= $offset;
		}
		// this wrapper needs to return "true" for success.
		// the fseek call itself returns 0 on succeess
		return fseek($this->source, $offset, $whence) === 0;
	}

	public function stream_tell() {
		return ftell($this->source);
	}

	public function stream_read($count) {
		$this->limit -= $count;
		return fread($this->source, $count);
	}

	public function stream_write($data) {
		$size = strlen($data);
		if ($size > $this->limit) {
			$data = substr($data, 0, $this->limit);
			$size = $this->limit;
		}
		$this->limit -= $size;
		return fwrite($this->source, $data);
	}

	public function stream_set_option($option, $arg1, $arg2) {
		switch ($option) {
			case STREAM_OPTION_BLOCKING:
				stream_set_blocking($this->source, $arg1);
				break;
			case STREAM_OPTION_READ_TIMEOUT:
				stream_set_timeout($this->source, $arg1, $arg2);
				break;
			case STREAM_OPTION_WRITE_BUFFER:
				stream_set_write_buffer($this->source, $arg1, $arg2);
		}
	}

	public function stream_stat() {
		return fstat($this->source);
	}

	public function stream_lock($mode) {
		return flock($this->source, $mode);
	}

	public function stream_flush() {
		return fflush($this->source);
	}

	public function stream_eof() {
		return feof($this->source);
	}

	public function stream_close() {
		fclose($this->source);
	}
}