mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(cli): --ignore getting ignored (#9071)
This commit is contained in:
parent
a0d03925e0
commit
c14a2eda5d
7 changed files with 69 additions and 340 deletions
|
|
@ -26,7 +26,7 @@ type Asset = { id: string; filepath: string };
|
|||
|
||||
interface UploadOptionsDto {
|
||||
recursive?: boolean;
|
||||
exclusionPatterns?: string[];
|
||||
ignore?: string;
|
||||
dryRun?: boolean;
|
||||
skipHash?: boolean;
|
||||
delete?: boolean;
|
||||
|
|
@ -75,7 +75,7 @@ const scan = async (pathsToCrawl: string[], options: UploadOptionsDto) => {
|
|||
const files = await crawl({
|
||||
pathsToCrawl,
|
||||
recursive: options.recursive,
|
||||
exclusionPatterns: options.exclusionPatterns,
|
||||
exclusionPattern: options.ignore,
|
||||
includeHidden: options.includeHidden,
|
||||
extensions: [...image, ...video],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ program
|
|||
.description('Upload assets')
|
||||
.usage('[paths...] [options]')
|
||||
.addOption(new Option('-r, --recursive', 'Recursive').env('IMMICH_RECURSIVE').default(false))
|
||||
.addOption(new Option('-i, --ignore [paths...]', 'Paths to ignore').env('IMMICH_IGNORE_PATHS').default([]))
|
||||
.addOption(new Option('-i, --ignore <pattern>', 'Pattern to ignore').env('IMMICH_IGNORE_PATHS'))
|
||||
.addOption(new Option('-h, --skip-hash', "Don't hash files before upload").env('IMMICH_SKIP_HASH').default(false))
|
||||
.addOption(new Option('-H, --include-hidden', 'Include hidden folders').env('IMMICH_INCLUDE_HIDDEN').default(false))
|
||||
.addOption(
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ const tests: Test[] = [
|
|||
test: 'should exclude by file extension',
|
||||
options: {
|
||||
pathsToCrawl: ['/photos/'],
|
||||
exclusionPatterns: ['**/*.tif'],
|
||||
exclusionPattern: '**/*.tif',
|
||||
},
|
||||
files: {
|
||||
'/photos/image.jpg': true,
|
||||
|
|
@ -77,7 +77,7 @@ const tests: Test[] = [
|
|||
test: 'should exclude by file extension without case sensitivity',
|
||||
options: {
|
||||
pathsToCrawl: ['/photos/'],
|
||||
exclusionPatterns: ['**/*.TIF'],
|
||||
exclusionPattern: '**/*.TIF',
|
||||
},
|
||||
files: {
|
||||
'/photos/image.jpg': true,
|
||||
|
|
@ -88,7 +88,7 @@ const tests: Test[] = [
|
|||
test: 'should exclude by folder',
|
||||
options: {
|
||||
pathsToCrawl: ['/photos/'],
|
||||
exclusionPatterns: ['**/raw/**'],
|
||||
exclusionPattern: '**/raw/**',
|
||||
recursive: true,
|
||||
},
|
||||
files: {
|
||||
|
|
@ -218,7 +218,7 @@ const tests: Test[] = [
|
|||
test: 'should support ignoring full filename',
|
||||
options: {
|
||||
pathsToCrawl: ['/photos'],
|
||||
exclusionPatterns: ['**/image2.jpg'],
|
||||
exclusionPattern: '**/image2.jpg',
|
||||
},
|
||||
files: {
|
||||
'/photos/image1.jpg': true,
|
||||
|
|
@ -230,7 +230,7 @@ const tests: Test[] = [
|
|||
test: 'should support ignoring file extensions',
|
||||
options: {
|
||||
pathsToCrawl: ['/photos'],
|
||||
exclusionPatterns: ['**/*.png'],
|
||||
exclusionPattern: '**/*.png',
|
||||
},
|
||||
files: {
|
||||
'/photos/image1.jpg': true,
|
||||
|
|
@ -243,7 +243,7 @@ const tests: Test[] = [
|
|||
options: {
|
||||
pathsToCrawl: ['/photos'],
|
||||
recursive: true,
|
||||
exclusionPatterns: ['**/raw/**'],
|
||||
exclusionPattern: '**/raw/**',
|
||||
},
|
||||
files: {
|
||||
'/photos/image1.jpg': true,
|
||||
|
|
@ -258,7 +258,7 @@ const tests: Test[] = [
|
|||
options: {
|
||||
pathsToCrawl: ['/'],
|
||||
recursive: true,
|
||||
exclusionPatterns: ['/images/**'],
|
||||
exclusionPattern: '/images/**',
|
||||
},
|
||||
files: {
|
||||
'/photos/image1.jpg': true,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { defaults, getMyUserInfo, isHttpError } from '@immich/sdk';
|
||||
import { glob } from 'glob';
|
||||
import { glob } from 'fast-glob';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import { readFile, stat, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { join, resolve } from 'node:path';
|
||||
import yaml from 'yaml';
|
||||
|
||||
export interface BaseOptions {
|
||||
|
|
@ -104,11 +104,11 @@ export interface CrawlOptions {
|
|||
pathsToCrawl: string[];
|
||||
recursive?: boolean;
|
||||
includeHidden?: boolean;
|
||||
exclusionPatterns?: string[];
|
||||
exclusionPattern?: string;
|
||||
extensions: string[];
|
||||
}
|
||||
export const crawl = async (options: CrawlOptions): Promise<string[]> => {
|
||||
const { extensions: extensionsWithPeriod, recursive, pathsToCrawl, exclusionPatterns, includeHidden } = options;
|
||||
const { extensions: extensionsWithPeriod, recursive, pathsToCrawl, exclusionPattern, includeHidden } = options;
|
||||
const extensions = extensionsWithPeriod.map((extension) => extension.replace('.', ''));
|
||||
|
||||
if (pathsToCrawl.length === 0) {
|
||||
|
|
@ -120,11 +120,12 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => {
|
|||
|
||||
for await (const currentPath of pathsToCrawl) {
|
||||
try {
|
||||
const stats = await stat(currentPath);
|
||||
const absolutePath = resolve(currentPath);
|
||||
const stats = await stat(absolutePath);
|
||||
if (stats.isFile() || stats.isSymbolicLink()) {
|
||||
crawledFiles.push(currentPath);
|
||||
crawledFiles.push(absolutePath);
|
||||
} else {
|
||||
patterns.push(currentPath);
|
||||
patterns.push(absolutePath);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.code === 'ENOENT') {
|
||||
|
|
@ -152,13 +153,13 @@ export const crawl = async (options: CrawlOptions): Promise<string[]> => {
|
|||
|
||||
const globbedFiles = await glob(searchPattern, {
|
||||
absolute: true,
|
||||
nocase: true,
|
||||
nodir: true,
|
||||
caseSensitiveMatch: false,
|
||||
onlyFiles: true,
|
||||
dot: includeHidden,
|
||||
ignore: exclusionPatterns,
|
||||
ignore: [`**/${exclusionPattern}`],
|
||||
});
|
||||
|
||||
return [...crawledFiles, ...globbedFiles].sort();
|
||||
globbedFiles.push(...crawledFiles);
|
||||
return globbedFiles.sort();
|
||||
};
|
||||
|
||||
export const sha1 = (filepath: string) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue