Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
c267c858
Commit
c267c858
authored
Dec 15, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-241: Delete orphan chunks if GridFS upload fails
parent
6676e7ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
WritableStream.php
src/GridFS/WritableStream.php
+22
-3
No files found.
src/GridFS/WritableStream.php
View file @
c267c858
...
@@ -5,6 +5,7 @@ namespace MongoDB\GridFS;
...
@@ -5,6 +5,7 @@ namespace MongoDB\GridFS;
use
MongoDB\BSON\Binary
;
use
MongoDB\BSON\Binary
;
use
MongoDB\BSON\ObjectId
;
use
MongoDB\BSON\ObjectId
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\RuntimeException
;
...
@@ -175,7 +176,12 @@ class WritableStream
...
@@ -175,7 +176,12 @@ class WritableStream
private
function
abort
()
private
function
abort
()
{
{
$this
->
collectionWrapper
->
deleteChunksByFilesId
(
$this
->
file
[
'_id'
]);
try
{
$this
->
collectionWrapper
->
deleteChunksByFilesId
(
$this
->
file
[
'_id'
]);
}
catch
(
DriverRuntimeException
$e
)
{
// We are already handling an error if abort() is called, so suppress this
}
$this
->
isClosed
=
true
;
$this
->
isClosed
=
true
;
}
}
...
@@ -191,7 +197,13 @@ class WritableStream
...
@@ -191,7 +197,13 @@ class WritableStream
$this
->
file
[
'length'
]
=
$this
->
length
;
$this
->
file
[
'length'
]
=
$this
->
length
;
$this
->
file
[
'md5'
]
=
$md5
;
$this
->
file
[
'md5'
]
=
$md5
;
$this
->
collectionWrapper
->
insertFile
(
$this
->
file
);
try
{
$this
->
collectionWrapper
->
insertFile
(
$this
->
file
);
}
catch
(
DriverRuntimeException
$e
)
{
$this
->
abort
();
throw
$e
;
}
return
$this
->
file
[
'_id'
];
return
$this
->
file
[
'_id'
];
}
}
...
@@ -218,7 +230,14 @@ class WritableStream
...
@@ -218,7 +230,14 @@ class WritableStream
hash_update
(
$this
->
ctx
,
$data
);
hash_update
(
$this
->
ctx
,
$data
);
$this
->
collectionWrapper
->
insertChunk
(
$chunk
);
try
{
$this
->
collectionWrapper
->
insertChunk
(
$chunk
);
}
catch
(
DriverRuntimeException
$e
)
{
$this
->
abort
();
throw
$e
;
}
$this
->
length
+=
strlen
(
$data
);
$this
->
length
+=
strlen
(
$data
);
$this
->
chunkOffset
++
;
$this
->
chunkOffset
++
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment