Indefero

Indefero Commit Details


Date:2011-11-18 18:13:22 (13 years 1 month ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:ff2b19d58760980227e80676613949cdda91b786
Parents: ba365af0205feb535f332510da922242a6c0f8a2
Message:The "exists file from archive in project" check was flawed because $name was overwritten. So, this was fixed by adding a special functionality when archive files are uploaded that replace existing files with equal names; these are now deleted. This is docuemented more clearly in the FAQ and it is also documented now that files in the archive that are not listed in the manifest are not extracted.

Changes:

File differences

src/IDF/Form/UploadArchive.php
5858
5959
6060
61
62
61
62
6363
6464
65
66
67
65
66
67
6868
6969
7070
......
7878
7979
8080
81
82
81
82
8383
8484
8585
......
100100
101101
102102
103
103
104104
105105
106
106
107
107108
108
109
109110
110111
111112
......
158159
159160
160161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
161180
162181
163182
......
175194
176195
177196
178
179
180
181
182
183
184
185
186
187
188
189
190
191197
192198
193199
$this->archiveHelper->validate();
// extension validation
$names = $this->archiveHelper->getEntryNames();
foreach ($names as $name) {
$fileNames = $this->archiveHelper->getEntryNames();
foreach ($fileNames as $fileName) {
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
if (strlen($extra)) $extra .= '|';
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $name)) {
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
throw new Pluf_Form_Invalid(sprintf(__('For security reasons, you cannot upload a file (%s) with this extension.'), $name));
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $fileName)) {
@unlink(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['archive']);
throw new Pluf_Form_Invalid(sprintf(__('For security reasons, you cannot upload a file (%s) with this extension.'), $fileName));
}
}
}
}
foreach ($names as $name) {
$meta = $this->archiveHelper->getMetaData($name);
foreach ($fileNames as $fileName) {
$meta = $this->archiveHelper->getMetaData($fileName);
$count = array();
foreach ($meta['labels'] as $label) {
$label = trim($label);
}
}
$sql = new Pluf_SQL('file=%s AND project=%s', array($name, $this->project->id));
$sql = new Pluf_SQL('file=%s AND project=%s', array($fileName, $this->project->id));
$upload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
if ($upload) {
$meta = $this->archiveHelper->getMetaData($fileName);
if ($upload != null && $meta['replaces'] !== $fileName) {
throw new Pluf_Form_Invalid(
sprintf(__('A file with the name "%s" has already been uploaded.'), $name));
sprintf(__('A file with the name "%s" has already been uploaded and is not marked to be replaced.'), $fileName));
}
}
}
}
// process a possible replacement
if (!empty($meta['replaces'])) {
$sql = new Pluf_SQL('file=%s AND project=%s', array($meta['replaces'], $this->project->id));
$oldUpload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
if ($oldUpload) {
if ($meta['replaces'] === $fileName) {
$oldUpload->delete();
} else {
$tags = $this->project->getTagsFromConfig('labels_download_predefined',
IDF_Form_UploadConf::init_predefined);
// the deprecate tag is - by definition - always the last one
$deprecatedTag = array_pop($tags);
$oldUpload->setAssoc($deprecatedTag);
}
}
}
// extract the file
$this->archiveHelper->extract($fileName, $uploadDir);
$upload->setAssoc($tag);
}
// process a possible replacement
if (!empty($meta['replaces'])) {
$sql = new Pluf_SQL('file=%s AND project=%s', array($meta['replaces'], $this->project->id));
$oldUpload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
if ($oldUpload) {
$tags = $this->project->getTagsFromConfig('labels_download_predefined',
IDF_Form_UploadConf::init_predefined);
// the deprecate tag is - by definition - always the last one
$deprecatedTag = array_pop($tags);
$oldUpload->setAssoc($deprecatedTag);
}
}
// send the notification
$upload->notify($this->project->getConf());
/**
src/IDF/templates/idf/faq-archive-format.html
2525
2626
2727
28
29
28
29
30
3031
3132
3233
......
8586
8687
8788
88
89
90
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
91105
92106
93107
<p>
Once such an archive has been uploaded and validated by InDefero, its files are extracted
and individual downloads are created for each of them. If the archive contains files
that should deprecate existing downloads, then InDefero takes care of this as well -
automatically.
that should replace existing downloads, then InDefero takes care of this as well -
automatically. Files that exist in the archive but are not listed in the manifest are
not extracted.
</p>
<p>
<p>
The format is more or less self-explaining, all fields map to properties of a single download.
One special element has been introduced though, <code>replaces</code>. If this optional element
is given, InDefero looks for a file with that name in the project and deprecates it by attaching
the label <code>Other:Deprecated</code> to it. If no such file is found, the element is simply
ignored.
is given, InDefero looks for a file with that name in the project and acts in one of the following
two ways:
</p>
<ul>
<li>If the new file's name is distinct from the file's name that is given in <code>replaces</code>,
then the replaced file is <strong>marked as deprecated</strong> with the <code>Other:Deprecated</code> label
(or any other label that is configured as the very last label in the download project configuration).</li>
<li>If the new file's name is equal to the file's name that is given in <code>replaces</code>,
then the replaced file <strong>is deleted</strong> before the new file is created. This happens because each file name
has to be unique per project and a deprecated and a new file with the same name cannot coexist in InDefero.
Note that while the filename-based URI of the download keeps intact, the download counter will be reset by
this procedure.</li>
</ul>
If no existing file is found for the <code>replaces</code> tag, then this is completely ignored.
</p>
{/block}

Archive Download the corresponding diff file

Page rendered in 0.08375s using 13 queries.