summaryrefslogtreecommitdiffstats
path: root/application/models/mfile.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-11-08 17:25:31 +0100
committerFlorian Pritz <bluewind@xinu.at>2014-11-28 14:51:03 +0100
commite60b5468afe0a0d6aa9dab2e6dcf9d186dd168fd (patch)
tree10f8edd85a0758a86f60ee113457766bee322d1d /application/models/mfile.php
parenta6655941189e692c4ff06aa41a65e4ac7f0e82fd (diff)
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models/mfile.php')
-rw-r--r--application/models/mfile.php53
1 files changed, 31 insertions, 22 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index eee2c4e5b..d6851a6ef 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -70,27 +70,30 @@ class Mfile extends CI_Model {
function get_filedata($id)
{
$query = $this->db
- ->select('id, hash, filename, mimetype, date, user, filesize')
+ ->select('files.id, hash, hash_collision_counter, filename, mimetype, date, user, filesize')
->from('files')
- ->where('id', $id)
+ ->join('file_storage', 'file_storage.id = files.file_storage_id')
+ ->where('files.id', $id)
->limit(1)
->get();
if ($query->num_rows() > 0) {
- return $query->row_array();
+ $data = $query->row_array();
+ $data["data_id"] = $data["hash"]."-".$data["hash_collision_counter"];
+ return $data;
} else {
return false;
}
}
- // return the folder in which the file with $hash is stored
- function folder($hash) {
- return $this->config->item('upload_path').'/'.substr($hash, 0, 3);
+ // return the folder in which the file with $data_id is stored
+ function folder($data_id) {
+ return $this->config->item('upload_path').'/'.substr($data_id, 0, 3);
}
- // Returns the full path to the file with $hash
- function file($hash) {
- return $this->folder($hash).'/'.$hash;
+ // Returns the full path to the file with $data_id
+ function file($data_id) {
+ return $this->folder($data_id).'/'.$data_id;
}
// Return mimetype of file
@@ -136,10 +139,10 @@ class Mfile extends CI_Model {
if (!$filedata) {
return false;
}
- $file = $this->file($filedata['hash']);
+ $file = $this->file($filedata['data_id']);
if (!file_exists($file)) {
- $this->delete_hash($filedata["hash"]);
+ $this->delete_data_id($filedata["data_id"]);
return false;
}
@@ -158,7 +161,7 @@ class Mfile extends CI_Model {
// if the file has been uploaded multiple times the mtime is the time
// of the last upload
if (filemtime($file) < $remove_before) {
- $this->delete_hash($filedata["hash"]);
+ $this->delete_data_id($filedata["data_id"]);
} else {
$this->delete_id($id);
}
@@ -171,7 +174,7 @@ class Mfile extends CI_Model {
public function get_timeout($id)
{
$filedata = $this->get_filedata($id);
- $file = $this->file($filedata["hash"]);
+ $file = $this->file($filedata["data_id"]);
if ($this->config->item("upload_max_age") == 0) {
return -1;
@@ -195,11 +198,14 @@ class Mfile extends CI_Model {
}
}
- private function unused_file($hash)
+ private function unused_file($data_id)
{
- $query = $this->db->select('id')
+ list ($hash, $hash_collision_counter) = explode("-", $data_id);
+ $query = $this->db->select('files.id')
->from('files')
+ ->join('file_storage', 'file_storage.id = files.file_storage_id')
->where('hash', $hash)
+ ->where('hash_collision_counter', $hash_collision_counter)
->limit(1)
->get();
@@ -238,12 +244,12 @@ class Mfile extends CI_Model {
}
if ($filedata !== false) {
- assert(isset($filedata["hash"]));
- if ($this->unused_file($filedata['hash'])) {
- if (file_exists($this->file($filedata['hash']))) {
- unlink($this->file($filedata['hash']));
+ assert(isset($filedata["data_id"]));
+ if ($this->unused_file($filedata['data_id'])) {
+ if (file_exists($this->file($filedata['data_id']))) {
+ unlink($this->file($filedata['data_id']));
}
- $dir = $this->folder($filedata['hash']);
+ $dir = $this->folder($filedata['data_id']);
if (file_exists($dir)) {
if (count(scandir($dir)) == 2) {
rmdir($dir);
@@ -254,11 +260,14 @@ class Mfile extends CI_Model {
return true;
}
- public function delete_hash($hash)
+ public function delete_data_id($data_id)
{
- $ids = $this->db->select('id')
+ list ($hash, $hash_collision_counter) = explode("-", $data_id);
+ $ids = $this->db->select('files.id')
->from('files')
+ ->join('file_storage', 'file_storage.id = files.file_storage_id')
->where('hash', $hash)
+ ->where('hash_collision_counter', $hash_collision_counter)
->get()->result_array();
foreach ($ids as $entry) {