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 ;
11
12
use Symfony \Component \HttpFoundation \StreamedResponse ;
12
13
13
14
class LogFile
@@ -16,25 +17,28 @@ class LogFile
16
17
use Concerns \LogFile \CanCacheData;
17
18
18
19
public string $ path ;
19
-
20
20
public string $ name ;
21
-
22
21
public string $ identifier ;
23
-
22
+ public string $ absolutePath = '' ;
24
23
public string $ subFolder = '' ;
25
-
26
24
private array $ _logIndexCache ;
27
25
28
26
public function __construct (string $ path )
29
27
{
28
+ $ pathInfo = pathinfo ($ path );
30
29
$ this ->path = $ path ;
31
- $ this ->name = basename ( $ path ) ;
30
+ $ this ->name = $ pathInfo [ ' basename ' ] ;
32
31
$ this ->identifier = Str::substr (md5 ($ path ), -8 , 8 ).'- ' .$ this ->name ;
33
32
34
33
// Let's remove the file name because we already know it.
35
34
$ this ->subFolder = str_replace ($ this ->name , '' , $ path );
36
35
$ this ->subFolder = rtrim ($ this ->subFolder , DIRECTORY_SEPARATOR );
37
36
37
+ if (str_starts_with ($ path , DIRECTORY_SEPARATOR )) {
38
+ $ this ->absolutePath = pathinfo ($ path )['dirname ' ];
39
+ $ this ->path = pathinfo ($ path )['basename ' ];
40
+ }
41
+
38
42
$ this ->loadMetadata ();
39
43
}
40
44
@@ -54,9 +58,7 @@ public function logs(): LogReader
54
58
55
59
public function size (): int
56
60
{
57
- return LogViewer::getFilesystem ()->exists ($ this ->path )
58
- ? LogViewer::getFilesystem ()->size ($ this ->path )
59
- : 0 ;
61
+ return LogViewer::getFilesystem ($ this ->absolutePath )->size ($ this ->path );
60
62
}
61
63
62
64
public function sizeInMB (): float
@@ -81,7 +83,7 @@ public function downloadUrl(): string
81
83
82
84
public function download (): StreamedResponse
83
85
{
84
- return LogViewer::getFilesystem ()->download ($ this ->path );
86
+ return LogViewer::getFilesystem ($ this -> absolutePath )->download ($ this ->path );
85
87
}
86
88
87
89
public function addRelatedIndex (LogIndex $ logIndex ): void
@@ -109,15 +111,13 @@ public function getLastScannedFilePositionForQuery(?string $query = ''): ?int
109
111
public function earliestTimestamp (): int
110
112
{
111
113
return $ this ->getMetadata ('earliest_timestamp ' )
112
- ?? 0 ;
113
- // ?? LogViewer::getFilesystem()->exists($this->path) ? LogViewer::getFilesystem()->lastModified($this->path) : 0;
114
+ ?? LogViewer::getFilesystem ($ this ->absolutePath )->lastModified ($ this ->path );
114
115
}
115
116
116
117
public function latestTimestamp (): int
117
118
{
118
119
return $ this ->getMetadata ('latest_timestamp ' )
119
- ?? 0 ;
120
- // ?? LogViewer::getFilesystem()->exists($this->path) ? LogViewer::getFilesystem()->lastModified($this->path) : 0;
120
+ ?? LogViewer::getFilesystem ($ this ->absolutePath )->lastModified ($ this ->path );
121
121
}
122
122
123
123
public function scan (int $ maxBytesToScan = null , bool $ force = false ): void
@@ -141,7 +141,7 @@ public function search(string $query = null): LogReader
141
141
public function delete (): void
142
142
{
143
143
$ this ->clearCache ();
144
- LogViewer::getFilesystem ()->delete ($ this ->path );
144
+ LogViewer::getFilesystem ($ this -> absolutePath )->delete ($ this ->path );
145
145
LogFileDeleted::dispatch ($ this );
146
146
}
147
147
}
0 commit comments