|
17 | 17 | */ |
18 | 18 |
|
19 | 19 | // jshint ignore: start |
20 | | -/*global TextDecoder, buffer, globalObject*/ |
| 20 | +/*global buffer, globalObject*/ |
21 | 21 | /*eslint no-console: 0*/ |
22 | 22 | /*eslint strict: ["error", "global"]*/ |
23 | 23 |
|
@@ -261,41 +261,46 @@ async function unlink(path, callback) { |
261 | 261 | } |
262 | 262 |
|
263 | 263 | async function _getDestinationHandleForCopy(dst, srcBaseName, handleKindToCreate) { |
264 | | - return new Promise(async (resolve, reject) => { |
265 | | - dst = globalObject.path.normalize(dst); |
266 | | - let dirPath= globalObject.path.dirname(dst); |
267 | | - let dstBaseName= globalObject.path.basename(dst); |
268 | | - let dstHandle = await Mounts.getHandleFromPathIfPresent(dst); |
269 | | - let dstParentHandle = await Mounts.getHandleFromPathIfPresent(dirPath); |
270 | | - if (dstHandle && dstHandle.kind === Constants.KIND_FILE) { |
271 | | - reject(new Errors.EEXIST(`Destination file already exists: ${dst}`)); |
272 | | - } else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY |
273 | | - && handleKindToCreate === Constants.KIND_FILE) { |
274 | | - const fileHandle = await dstHandle.getFileHandle(srcBaseName, {create: true}); |
275 | | - const dstPath = `${dst}/${srcBaseName}`; |
276 | | - resolve({handle: fileHandle, path:dstPath}); |
277 | | - } else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY |
278 | | - && handleKindToCreate === Constants.KIND_DIRECTORY) { |
279 | | - let dstChildHandle = await Mounts.getHandleFromPathIfPresent(`${dst}/${srcBaseName}`); |
280 | | - if(dstChildHandle){ |
281 | | - reject(new Errors.EEXIST(`Copy destination already exists: ${dst}/${srcBaseName}`)); |
282 | | - return; |
| 264 | + return new Promise(async (resolve, reject) => { // eslint-disable-line |
| 265 | + // eslint async executors are needed here. we explicitly catch so it's fine. |
| 266 | + try{ |
| 267 | + dst = globalObject.path.normalize(dst); |
| 268 | + let dirPath= globalObject.path.dirname(dst); |
| 269 | + let dstBaseName= globalObject.path.basename(dst); |
| 270 | + let dstHandle = await Mounts.getHandleFromPathIfPresent(dst); |
| 271 | + let dstParentHandle = await Mounts.getHandleFromPathIfPresent(dirPath); |
| 272 | + if (dstHandle && dstHandle.kind === Constants.KIND_FILE) { |
| 273 | + reject(new Errors.EEXIST(`Destination file already exists: ${dst}`)); |
| 274 | + } else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY |
| 275 | + && handleKindToCreate === Constants.KIND_FILE) { |
| 276 | + const fileHandle = await dstHandle.getFileHandle(srcBaseName, {create: true}); |
| 277 | + const dstPath = `${dst}/${srcBaseName}`; |
| 278 | + resolve({handle: fileHandle, path:dstPath}); |
| 279 | + } else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY |
| 280 | + && handleKindToCreate === Constants.KIND_DIRECTORY) { |
| 281 | + let dstChildHandle = await Mounts.getHandleFromPathIfPresent(`${dst}/${srcBaseName}`); |
| 282 | + if(dstChildHandle){ |
| 283 | + reject(new Errors.EEXIST(`Copy destination already exists: ${dst}/${srcBaseName}`)); |
| 284 | + return; |
| 285 | + } |
| 286 | + const directoryHandle = await dstHandle.getDirectoryHandle(srcBaseName, {create: true}); |
| 287 | + const dstPath = `${dst}/${srcBaseName}`; |
| 288 | + resolve({handle: directoryHandle, path: dstPath}); |
| 289 | + } else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY |
| 290 | + && handleKindToCreate === Constants.KIND_FILE) { |
| 291 | + const fileHandle = await dstParentHandle.getFileHandle(dstBaseName, {create: true}); |
| 292 | + const dstPath = `${dirPath}/${dstBaseName}`; |
| 293 | + resolve({handle: fileHandle, path: dstPath}); |
| 294 | + } else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY |
| 295 | + && handleKindToCreate === Constants.KIND_DIRECTORY) { |
| 296 | + const fileHandle = await dstParentHandle.getDirectoryHandle(dstBaseName, {create: true}); |
| 297 | + const dstPath = `${dirPath}/${dstBaseName}`; |
| 298 | + resolve({handle: fileHandle, path: dstPath}); |
| 299 | + } else { |
| 300 | + reject(new Errors.ENOENT(`Copy destination doesnt exist: ${dst}`)); |
283 | 301 | } |
284 | | - const directoryHandle = await dstHandle.getDirectoryHandle(srcBaseName, {create: true}); |
285 | | - const dstPath = `${dst}/${srcBaseName}`; |
286 | | - resolve({handle: directoryHandle, path: dstPath}); |
287 | | - } else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY |
288 | | - && handleKindToCreate === Constants.KIND_FILE) { |
289 | | - const fileHandle = await dstParentHandle.getFileHandle(dstBaseName, {create: true}); |
290 | | - const dstPath = `${dirPath}/${dstBaseName}`; |
291 | | - resolve({handle: fileHandle, path: dstPath}); |
292 | | - } else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY |
293 | | - && handleKindToCreate === Constants.KIND_DIRECTORY) { |
294 | | - const fileHandle = await dstParentHandle.getDirectoryHandle(dstBaseName, {create: true}); |
295 | | - const dstPath = `${dirPath}/${dstBaseName}`; |
296 | | - resolve({handle: fileHandle, path: dstPath}); |
297 | | - } else { |
298 | | - reject(new Errors.ENOENT(`Copy destination doesnt exist: ${dst}`)); |
| 302 | + } catch (e) { |
| 303 | + reject(e); |
299 | 304 | } |
300 | 305 | }); |
301 | 306 | } |
|
0 commit comments