Skip to content

Commit 2ea2d6e

Browse files
author
richard-jones
committed
Add clean up operation to deposit operations
All deposit operations which take a Deposit object now run a cleanup on the deposit object to remove any temp files that are created git-svn-id: http://sword-app.svn.sourceforge.net/svnroot/sword-app/JavaServer2.0/trunk@498 2bf6ea0f-123d-0410-b71a-f1a21eb24612
1 parent 4721ee7 commit 2ea2d6e

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

src/main/java/org/swordapp/server/CollectionAPI.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
122122
}
123123
}
124124

125+
Deposit deposit = null;
125126
try
126127
{
127128
// the first thing to do is determine what the deposit type is:
@@ -134,7 +135,7 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
134135
String slug = req.getHeader("Slug");
135136
boolean inProgress = this.getInProgress(req);
136137

137-
Deposit deposit = new Deposit();
138+
deposit = new Deposit();
138139
deposit.setInProgress(inProgress);
139140
deposit.setSlug(slug);
140141
DepositReceipt receipt = null;
@@ -213,6 +214,11 @@ else if (isBinaryOnly)
213214
// need to throw a 403 Forbidden
214215
resp.sendError(403);
215216
}
217+
finally
218+
{
219+
// get rid of any temp files used
220+
this.cleanup(deposit);
221+
}
216222
}
217223
protected void addGenerator(DepositReceipt doc, SwordConfiguration config)
218224
{

src/main/java/org/swordapp/server/ContainerAPI.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public void put(HttpServletRequest req, HttpServletResponse resp)
179179
}
180180
}
181181

182+
Deposit deposit = null;
182183
try
183184
{
184185
// the first thing to do is determine what the deposit type is:
@@ -189,7 +190,7 @@ public void put(HttpServletRequest req, HttpServletResponse resp)
189190
// get the In-Progress header
190191
boolean inProgress = this.getInProgress(req);
191192

192-
Deposit deposit = new Deposit();
193+
deposit = new Deposit();
193194
deposit.setInProgress(inProgress);
194195
String iri = this.getFullUrl(req);
195196
DepositReceipt receipt;
@@ -277,6 +278,11 @@ else if (isEntryOnly)
277278
// need to throw a 403 Forbidden
278279
resp.sendError(403);
279280
}
281+
finally
282+
{
283+
// get rid of any temp files used
284+
this.cleanup(deposit);
285+
}
280286
}
281287

282288
public void post(HttpServletRequest req, HttpServletResponse resp)
@@ -304,6 +310,7 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
304310
}
305311
}
306312

313+
Deposit deposit = null;
307314
try
308315
{
309316
// the first thing to do is determine what the deposit type is:
@@ -321,7 +328,7 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
321328
boolean inProgress = this.getInProgress(req);
322329
String iri = this.getFullUrl(req);
323330

324-
Deposit deposit = new Deposit();
331+
deposit = new Deposit();
325332
deposit.setInProgress(inProgress);
326333
DepositReceipt receipt;
327334

@@ -400,6 +407,11 @@ else if (headersOnly)
400407
// need to throw a 403 Forbidden
401408
resp.sendError(403);
402409
}
410+
finally
411+
{
412+
// get rid of any temp files used
413+
this.cleanup(deposit);
414+
}
403415
}
404416

405417
public void delete(HttpServletRequest req, HttpServletResponse resp)

src/main/java/org/swordapp/server/MediaResourceAPI.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ public void put(HttpServletRequest req, HttpServletResponse resp)
156156
}
157157
}
158158

159+
Deposit deposit = null;
160+
159161
try
160162
{
161163
String editMediaIRI = this.getFullUrl(req);
162-
Deposit deposit = new Deposit();
164+
deposit = new Deposit();
163165

164166
// add the properties from the binary deposit
165167
this.addDepositPropertiesFromBinary(deposit, req);
@@ -186,6 +188,11 @@ public void put(HttpServletRequest req, HttpServletResponse resp)
186188
// need to throw a 403 Forbidden
187189
resp.sendError(403);
188190
}
191+
finally
192+
{
193+
// get rid of any temp files used
194+
this.cleanup(deposit);
195+
}
189196
}
190197

191198
public void post(HttpServletRequest req, HttpServletResponse resp)
@@ -213,14 +220,15 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
213220
}
214221
}
215222

223+
Deposit deposit = null;
216224
try
217225
{
218226
// the first thing to do is determine what the deposit type is:
219227
String contentType = this.getContentType(req);
220228
boolean isMultipart = contentType.startsWith("multipart/related");
221229
String uri = this.getFullUrl(req);
222230

223-
Deposit deposit = new Deposit();
231+
deposit = new Deposit();
224232

225233
if (isMultipart)
226234
{
@@ -275,6 +283,11 @@ public void post(HttpServletRequest req, HttpServletResponse resp)
275283
// need to throw a 403 Forbidden
276284
resp.sendError(403);
277285
}
286+
finally
287+
{
288+
// get rid of any temp files used
289+
this.cleanup(deposit);
290+
}
278291
}
279292

280293
public void delete(HttpServletRequest req, HttpServletResponse resp)

src/main/java/org/swordapp/server/SwordAPIEndpoint.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ else if ("payload".equals(name))
257257
}
258258
}
259259

260+
protected void cleanup(Deposit deposit)
261+
{
262+
if (deposit == null)
263+
{
264+
return;
265+
}
266+
267+
File tmp = deposit.getFile();
268+
if (tmp == null)
269+
{
270+
return;
271+
}
272+
273+
tmp.delete();
274+
}
275+
260276
protected Element getGenerator(SwordConfiguration config)
261277
{
262278
String generatorUri = config.generator();

0 commit comments

Comments
 (0)