Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checksums #21997

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/dav/lib/connector/sabre/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ public function put($data) {
header('X-OC-MTime: accepted');
}
}

if (isset($request->server['HTTP_OC_CHECKSUM'])) {
$checksum = trim($request->server['HTTP_OC_CHECKSUM']);
$this->fileView->putFileInfo($this->path, ['checksum' => $checksum]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to a separate function. There are two code paths for Webdav PUT: this one is non-chunking and the other one goes into createFileChunked

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah yes...

$this->refreshInfo();

} catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage());
}
Expand Down Expand Up @@ -528,4 +534,13 @@ private function convertToSabreException(\Exception $e) {

throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
}

/**
* Get the checksum for this file
*
* @return string
*/
public function getChecksum() {
return $this->info->getChecksum();
}
}
24 changes: 22 additions & 2 deletions apps/dav/lib/connector/sabre/filesplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
const CHECKSUM_PROPERTYNAME = '{http://owncloud.org/ns}checksum';

/**
* Reference to main server object
Expand Down Expand Up @@ -107,6 +108,7 @@ public function initialize(\Sabre\DAV\Server $server) {
$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
$server->protectedProperties[] = self::CHECKSUM_PROPERTYNAME;

// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag'];
Expand Down Expand Up @@ -178,8 +180,8 @@ function handleDownloadToken(RequestInterface $request, ResponseInterface $respo
}

/**
* Plugin that adds a 'Content-Disposition: attachment' header to all files
* delivered by SabreDAV.
* Add headers to file download
*
* @param RequestInterface $request
* @param ResponseInterface $response
*/
Expand All @@ -188,7 +190,15 @@ function httpGet(RequestInterface $request, ResponseInterface $response) {
$node = $this->tree->getNodeForPath($request->getPath());
if (!($node instanceof IFile)) return;

// adds a 'Content-Disposition: attachment' header
$response->addHeader('Content-Disposition', 'attachment');

//Add OC-Checksum header
/** @var $node File */
$checksum = $node->getChecksum();
if ($checksum !== null) {
$response->addHeader('OC-Checksum', $checksum);
}
}

/**
Expand Down Expand Up @@ -237,6 +247,16 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
}
return false;
});

$propFind->handle(self::CHECKSUM_PROPERTYNAME, function() use ($node) {
$checksum = $node->getChecksum();

if ($checksum === null) {
return '';
}
return $checksum;
});

}

if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
Expand Down
8 changes: 8 additions & 0 deletions db_structure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@
<length>4</length>
</field>

<field>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is actually the part above it that has the weird indent ;) If you look at the wholefile.

<name>checksum</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>255</length>
</field>


<index>
<name>fs_storage_path_hash</name>
Expand Down
17 changes: 10 additions & 7 deletions lib/private/files/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function get($file) {
$params = array($file);
}
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`storage_mtime`, `encrypted`, `etag`, `permissions`
`storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`
FROM `*PREFIX*filecache` ' . $where;
$result = $this->connection->executeQuery($sql, $params);
$data = $result->fetch();
Expand Down Expand Up @@ -177,7 +177,7 @@ public function getFolderContents($folder) {
public function getFolderContentsById($fileId) {
if ($fileId > -1) {
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`storage_mtime`, `encrypted`, `etag`, `permissions`
`storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`
FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
$result = $this->connection->executeQuery($sql, [$fileId]);
$files = $result->fetchAll();
Expand Down Expand Up @@ -287,7 +287,10 @@ public function update($id, array $data) {
// don't update if the data we try to set is the same as the one in the record
// some databases (Postgres) don't like superfluous updates
$sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' .
'WHERE (' . implode(' <> ? OR ', $queryParts) . ' <> ? ) AND `fileid` = ? ';
'WHERE (' .
implode(' <> ? OR ', $queryParts) . ' <> ? OR ' .
implode(' IS NULL OR ', $queryParts) . ' IS NULL' .
') AND `fileid` = ? ';
$this->connection->executeQuery($sql, $params);

}
Expand All @@ -303,7 +306,7 @@ public function update($id, array $data) {
protected function buildParts(array $data) {
$fields = array(
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
'etag', 'permissions');
'etag', 'permissions', 'checksum');

$doNotCopyStorageMTime = false;
if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
Expand Down Expand Up @@ -567,7 +570,7 @@ public function search($pattern) {
$sql = '
SELECT `fileid`, `storage`, `path`, `parent`, `name`,
`mimetype`, `mimepart`, `size`, `mtime`, `encrypted`,
`etag`, `permissions`
`etag`, `permissions`, `checksum`
FROM `*PREFIX*filecache`
WHERE `storage` = ? AND `name` ILIKE ?';
$result = $this->connection->executeQuery($sql,
Expand Down Expand Up @@ -598,7 +601,7 @@ public function searchByMime($mimetype) {
} else {
$where = '`mimepart` = ?';
}
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
$mimetype = $this->mimetypeLoader->getId($mimetype);
$result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId()));
Expand All @@ -625,7 +628,7 @@ public function searchByMime($mimetype) {
public function searchByTag($tag, $userId) {
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' .
'`mimetype`, `mimepart`, `size`, `mtime`, ' .
'`encrypted`, `etag`, `permissions` ' .
'`encrypted`, `etag`, `permissions`, `checksum` ' .
'FROM `*PREFIX*filecache` `file`, ' .
'`*PREFIX*vcategory_to_object` `tagmap`, ' .
'`*PREFIX*vcategory` `tag` ' .
Expand Down
7 changes: 7 additions & 0 deletions lib/private/files/fileinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,11 @@ public function addSubEntry($data, $entryPath) {
$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
}
}

/**
* @inheritdoc
*/
public function getChecksum() {
return $this->data['checksum'];
}
}
7 changes: 7 additions & 0 deletions lib/private/files/node/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,11 @@ public function move($targetPath) {
public function hash($type, $raw = false) {
return $this->view->hash($type, $this->path, $raw);
}

/**
* @inheritdoc
*/
public function getChecksum() {
return $this->fileInfo->getChecksum();
}
}
4 changes: 4 additions & 0 deletions lib/private/files/node/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,8 @@ public function getMountPoint() {
public function getOwner() {
return $this->getFileInfo()->getOwner();
}

public function getChecksum() {
return;
}
}
8 changes: 8 additions & 0 deletions lib/public/files/fileinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,12 @@ public function getMountPoint();
* @since 9.0.0
*/
public function getOwner();

/**
* Get the stored checksum for this file
*
* @return string
* @since 9.0.0
*/
public function getChecksum();
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.
$OC_Version = array(9, 0, 0, 8);
$OC_Version = array(9, 0, 0, 9);

// The human readable string
$OC_VersionString = '9.0 pre alpha';
Expand Down