File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,10 @@ public function save()
103
103
104
104
try {
105
105
if ($ data ) {
106
- file_put_contents ($ this ->getFilePath (), serialize ($ data ));
106
+ $ path = $ this ->getFilePath ();
107
+ $ tmp = $ path .bin2hex (random_bytes (6 ));
108
+ file_put_contents ($ tmp , serialize ($ data ));
109
+ rename ($ tmp , $ path );
107
110
} else {
108
111
$ this ->destroy ();
109
112
}
@@ -123,8 +126,11 @@ public function save()
123
126
*/
124
127
private function destroy (): void
125
128
{
126
- if (is_file ($ this ->getFilePath ())) {
129
+ set_error_handler (static function () {});
130
+ try {
127
131
unlink ($ this ->getFilePath ());
132
+ } finally {
133
+ restore_error_handler ();
128
134
}
129
135
}
130
136
@@ -141,8 +147,14 @@ private function getFilePath(): string
141
147
*/
142
148
private function read (): void
143
149
{
144
- $ filePath = $ this ->getFilePath ();
145
- $ this ->data = is_readable ($ filePath ) && is_file ($ filePath ) ? unserialize (file_get_contents ($ filePath )) : [];
150
+ set_error_handler (static function () {});
151
+ try {
152
+ $ data = file_get_contents ($ this ->getFilePath ());
153
+ } finally {
154
+ restore_error_handler ();
155
+ }
156
+
157
+ $ this ->data = $ data ? unserialize ($ data ) : [];
146
158
147
159
$ this ->loadSession ();
148
160
}
You can’t perform that action at this time.
0 commit comments