blob: e43c3564a7d1f8d52a3cf420330739d042394609 (
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
|
<?php
/**
* Copyright (C) Piwik PRO - All rights reserved.
*
* Using this code requires that you first get a license from Piwik PRO.
* Unauthorized copying of this file, via any medium is strictly prohibited.
*
* @link http://piwik.pro
*/
namespace Piwik\Plugins\AutoLogImporter\LogImporter;
class File
{
public function getNumberOfLines($file)
{
if (!file_exists($file) || !is_readable($file)) {
return 0;
}
$numLines = 0;
$fileHandle = fopen($file, 'rb');
while (!feof($fileHandle)) {
$numLines += substr_count(fread($fileHandle, 8192), "\n");
}
// +1 for fist line
$numLines++;
fclose($fileHandle);
return $numLines;
}
public function getSize($file)
{
return filesize($file);
}
public function getHash($file)
{
return md5_file($file);
}
public function getPathToVerifyHashFile($file)
{
return $file . '.hash';
}
public function getVerifyHash($file)
{
if (!$this->hasVerifyHash($file)) {
return;
}
$hash = file_get_contents($this->getPathToVerifyHashFile($file));
if (!empty($hash)) {
return trim($hash);
}
}
public function hasVerifyHash($file)
{
return file_exists($this->getPathToVerifyHashFile($file));
}
public function wasFileSuccessfullyCopiedViaFileSynchronizerPlugin($logFile, $hash)
{
$verifyHash = $this->getVerifyHash($logFile);
return !empty($verifyHash) && $verifyHash === trim($hash);
}
}
|