@@ -131,17 +131,13 @@ object CopyUtils extends Logging {
131
131
)
132
132
} else {
133
133
val result = Try {
134
- if (destFS.exists(destPath.getParent)) {
135
- destFS.mkdirs(destPath)
136
- DirectoryCopyResult (
137
- definition.source.getPath.toUri,
138
- definition.destination,
139
- CopyActionResult .Created
140
- )
141
- } else
142
- throw new FileNotFoundException (
143
- s " Parent folder [ ${destPath.getParent}] does not exist. "
144
- )
134
+ options.missingDirectoryAction.requireDirectory(destFS, destPath.getParent)
135
+ options.missingDirectoryAction.createDirectory(destFS, destPath)
136
+ DirectoryCopyResult (
137
+ definition.source.getPath.toUri,
138
+ definition.destination,
139
+ CopyActionResult .Created
140
+ )
145
141
}
146
142
.recover { case _ : FileAlreadyExistsException =>
147
143
DirectoryCopyResult (
@@ -193,9 +189,9 @@ object CopyUtils extends Logging {
193
189
destFS,
194
190
definition.destination,
195
191
removeExisting = false ,
196
- ignoreErrors = options.ignoreErrors ,
192
+ options = options,
197
193
taskAttemptID
198
- )
194
+ )
199
195
case Failure (e) if options.ignoreErrors =>
200
196
logError(
201
197
s " Exception whilst getting destination file information [ ${definition.destination}] " ,
@@ -223,9 +219,9 @@ object CopyUtils extends Logging {
223
219
destFS,
224
220
definition.destination,
225
221
removeExisting = true ,
226
- ignoreErrors = options.ignoreErrors ,
222
+ options = options,
227
223
taskAttemptID
228
- )
224
+ )
229
225
case Success (d) if options.update =>
230
226
Try {
231
227
filesAreIdentical(
@@ -269,7 +265,7 @@ object CopyUtils extends Logging {
269
265
destFS,
270
266
definition.destination,
271
267
removeExisting = true ,
272
- ignoreErrors = options.ignoreErrors ,
268
+ options = options,
273
269
taskAttemptID
274
270
)
275
271
}
@@ -326,7 +322,7 @@ object CopyUtils extends Logging {
326
322
destFS : FileSystem ,
327
323
dest : URI ,
328
324
removeExisting : Boolean ,
329
- ignoreErrors : Boolean ,
325
+ options : SparkDistCPOptions ,
330
326
taskAttemptID : Long
331
327
): FileCopyResult = {
332
328
@@ -342,10 +338,7 @@ object CopyUtils extends Logging {
342
338
var out : Option [FSDataOutputStream ] = None
343
339
try {
344
340
in = Some (sourceFS.open(sourceFile.getPath))
345
- if (! destFS.exists(tempPath.getParent))
346
- throw new RuntimeException (
347
- s " Destination folder [ ${tempPath.getParent}] does not exist "
348
- )
341
+ options.missingDirectoryAction.requireDirectory(destFS, tempPath.getParent)
349
342
out = Some (destFS.create(tempPath, false ))
350
343
IOUtils .copyBytes(
351
344
in.get,
@@ -354,6 +347,7 @@ object CopyUtils extends Logging {
354
347
)
355
348
356
349
} catch {
350
+ case e : FileNotFoundException => throw new RuntimeException (e.getMessage)
357
351
case e : Throwable => throw e
358
352
} finally {
359
353
in.foreach(_.close())
@@ -397,7 +391,7 @@ object CopyUtils extends Logging {
397
391
sourceFile.len,
398
392
CopyActionResult .Copied
399
393
)
400
- case Failure (e) if ignoreErrors =>
394
+ case Failure (e) if options. ignoreErrors =>
401
395
logError(
402
396
s " Failed to copy file [ ${sourceFile.getPath}] to [ $destPath] " ,
403
397
e
0 commit comments