8
8
use Opcodes \LogViewer \Exceptions \InvalidRegularExpression ;
9
9
use Opcodes \LogViewer \Facades \LogViewer ;
10
10
use Opcodes \LogViewer \Utils \Utils ;
11
- use Symfony \Component \HttpFoundation \BinaryFileResponse ;
12
11
use Symfony \Component \HttpFoundation \StreamedResponse ;
13
12
14
13
class LogFile
@@ -17,21 +16,33 @@ class LogFile
17
16
use Concerns \LogFile \CanCacheData;
18
17
19
18
public string $ path ;
19
+
20
20
public string $ name ;
21
+
21
22
public string $ identifier ;
23
+
24
+ public string $ absolutePath = '' ;
25
+
22
26
public string $ subFolder = '' ;
27
+
23
28
private array $ _logIndexCache ;
24
29
25
30
public function __construct (string $ path )
26
31
{
32
+ $ pathInfo = pathinfo ($ path );
27
33
$ this ->path = $ path ;
28
- $ this ->name = basename ( $ path ) ;
34
+ $ this ->name = $ pathInfo [ ' basename ' ] ;
29
35
$ this ->identifier = Str::substr (md5 ($ path ), -8 , 8 ).'- ' .$ this ->name ;
30
36
31
37
// Let's remove the file name because we already know it.
32
38
$ this ->subFolder = str_replace ($ this ->name , '' , $ path );
33
39
$ this ->subFolder = rtrim ($ this ->subFolder , DIRECTORY_SEPARATOR );
34
40
41
+ if (str_starts_with ($ path , DIRECTORY_SEPARATOR )) {
42
+ $ this ->absolutePath = pathinfo ($ path )['dirname ' ];
43
+ $ this ->path = pathinfo ($ path )['basename ' ];
44
+ }
45
+
35
46
$ this ->loadMetadata ();
36
47
}
37
48
@@ -51,7 +62,9 @@ public function logs(): LogReader
51
62
52
63
public function size (): int
53
64
{
54
- return LogViewer::getFilesystem ()->size ($ this ->path );
65
+ return LogViewer::getFilesystem ($ this ->absolutePath )->exists ($ this ->path )
66
+ ? LogViewer::getFilesystem ($ this ->absolutePath )->size ($ this ->path )
67
+ : 0 ;
55
68
}
56
69
57
70
public function sizeInMB (): float
@@ -76,7 +89,7 @@ public function downloadUrl(): string
76
89
77
90
public function download (): StreamedResponse
78
91
{
79
- return LogViewer::getFilesystem ()->download ($ this ->path );
92
+ return LogViewer::getFilesystem ($ this -> absolutePath )->download ($ this ->path );
80
93
}
81
94
82
95
public function addRelatedIndex (LogIndex $ logIndex ): void
@@ -104,13 +117,13 @@ public function getLastScannedFilePositionForQuery(?string $query = ''): ?int
104
117
public function earliestTimestamp (): int
105
118
{
106
119
return $ this ->getMetadata ('earliest_timestamp ' )
107
- ?? LogViewer::getFilesystem ()->lastModified ($ this ->path );
120
+ ?? LogViewer::getFilesystem ($ this -> absolutePath )->exists ( $ this -> path ) ? LogViewer:: getFilesystem ( $ this -> absolutePath )-> lastModified ($ this ->path ) : 0 ;
108
121
}
109
122
110
123
public function latestTimestamp (): int
111
124
{
112
125
return $ this ->getMetadata ('latest_timestamp ' )
113
- ?? LogViewer::getFilesystem ()->lastModified ($ this ->path );
126
+ ?? LogViewer::getFilesystem ($ this -> absolutePath )->exists ( $ this -> path ) ? LogViewer:: getFilesystem ( $ this -> absolutePath )-> lastModified ($ this ->path ) : 0 ;
114
127
}
115
128
116
129
public function scan (int $ maxBytesToScan = null , bool $ force = false ): void
@@ -134,7 +147,7 @@ public function search(string $query = null): LogReader
134
147
public function delete (): void
135
148
{
136
149
$ this ->clearCache ();
137
- LogViewer::getFilesystem ()->delete ($ this ->path );
150
+ LogViewer::getFilesystem ($ this -> absolutePath )->delete ($ this ->path );
138
151
LogFileDeleted::dispatch ($ this );
139
152
}
140
153
}
0 commit comments