( rawPaths: string[], )
| 24 | } |
| 25 | |
| 26 | export async function validateAttachmentPaths( |
| 27 | rawPaths: string[], |
| 28 | ): Promise<ValidationResult> { |
| 29 | const cwd = getCwd() |
| 30 | for (const rawPath of rawPaths) { |
| 31 | const fullPath = expandPath(rawPath) |
| 32 | try { |
| 33 | const stats = await stat(fullPath) |
| 34 | if (!stats.isFile()) { |
| 35 | return { |
| 36 | result: false, |
| 37 | message: `Attachment "${rawPath}" is not a regular file.`, |
| 38 | errorCode: 1, |
| 39 | } |
| 40 | } |
| 41 | } catch (e) { |
| 42 | const code = getErrnoCode(e) |
| 43 | if (code === 'ENOENT') { |
| 44 | return { |
| 45 | result: false, |
| 46 | message: `Attachment "${rawPath}" does not exist. Current working directory: ${cwd}.`, |
| 47 | errorCode: 1, |
| 48 | } |
| 49 | } |
| 50 | if (code === 'EACCES' || code === 'EPERM') { |
| 51 | return { |
| 52 | result: false, |
| 53 | message: `Attachment "${rawPath}" is not accessible (permission denied).`, |
| 54 | errorCode: 1, |
| 55 | } |
| 56 | } |
| 57 | throw e |
| 58 | } |
| 59 | } |
| 60 | return { result: true } |
| 61 | } |
| 62 | |
| 63 | export async function resolveAttachments( |
| 64 | rawPaths: string[], |
no test coverage detected