Skip to content

An open-source cross-platform alternative to AirDrop

feat: deactivate sendignore

Tien Do Nam19b98d850b2c
diff --git a/app/lib/provider/selection/selected_sending_files_provider.dart b/app/lib/provider/selection/selected_sending_files_provider.dart
index 26fbb11b..fd02f975 100644
--- a/app/lib/provider/selection/selected_sending_files_provider.dart
+++ b/app/lib/provider/selection/selected_sending_files_provider.dart
@@ -9,7 +9,7 @@ import 'package:localsend_app/util/native/cache_helper.dart';
import 'package:localsend_app/util/native/channel/android_channel.dart' as android_channel;
import 'package:localsend_app/util/native/content_uri_helper.dart';
import 'package:localsend_app/util/native/cross_file_converters.dart';
-import 'package:localsend_app/util/native/send_ignore.dart';
+import 'package:localsend_app/util/send_ignore.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as p;
import 'package:refena_flutter/refena_flutter.dart';
@@ -153,12 +153,20 @@ class AddDirectoryAction extends AsyncReduxAction<SelectedSendingFilesNotifier,
_logger.info('Reading files in $directoryPath');
final newFiles = <CrossFile>[];
final directoryName = p.basename(directoryPath);
- final ignoreManager = IgnoreManager(directoryPath);
- final globs = await ignoreManager.getGlobs();
+ final sendIgnore = SendIgnore();
await for (final entity in Directory(directoryPath).list(recursive: true)) {
if (entity is File) {
- final relative = '$directoryName/${p.relative(entity.path, from: directoryPath).replaceAll('\\', '/')}';
- if (await checkIgnoreValidity(relative, globs)) {
+ final innerRelative = p.relative(entity.path, from: directoryPath).replaceAll('\\', '/');
+ final relative = '$directoryName/$innerRelative';
+ if (sendIgnore.isIgnoreFile(p.basename(entity.path))) {
+ sendIgnore.loadIgnoreContent(
+ parentPath: innerRelative.contains('/') ? p.dirname(innerRelative) : null,
+ ignoreContents: await entity.readAsLines(),
+ );
+ _logger.info('Loaded ignore file: $innerRelative');
+ continue;
+ } else if (sendIgnore.isIgnored(innerRelative)) {
+ _logger.info('Ignored: $innerRelative');
continue;
}
diff --git a/app/lib/util/native/send_ignore.dart b/app/lib/util/native/send_ignore.dart
deleted file mode 100644
index 0b776098..00000000
--- a/app/lib/util/native/send_ignore.dart
+++ /dev/null
@@ -1,62 +0,0 @@
-import 'dart:io';
-
-import 'package:glob/glob.dart';
-import 'package:path/path.dart' as p;
-
-const String ignoreName = '.sendignore';
-const String globalIgnoreDirectory = '';
-
-Future<bool> checkIgnoreValidity(String relativePath, Set<Glob> globs) async {
- return globs.any((glob) => glob.matches(relativePath));
-}
-
-class IgnoreManager {
- final String directoryPath;
-
- const IgnoreManager(this.directoryPath);
-
- Future<Set<Glob>> getGlobs() async {
- final availablePaths = ignorePathCandidates.skipWhile((ignorePath) => !File('$ignorePath/$ignoreName').existsSync()).toList();
- if (availablePaths.isEmpty) {
- return {};
- }
- final firstCandidate = availablePaths.first;
- // final String projectIgnorePath = '$directoryPath/$ignoreName';
- // if (!await File(projectIgnorePath).exists()) {
- // final String globalIgnorePath = '$globalIgnoreDirectory/$ignoreName';
- // if (!await File(globalIgnorePath).exists()) {
- // return {};
- // }
- // return SendIgnore(globalIgnorePath).globs;
- // }
- return SendIgnore(firstCandidate).globs;
- }
-
- List<String> get ignorePathCandidates {
- return [directoryPath, globalIgnoreDirectory];
- }
-}
-
-class SendIgnore {
- final String directoryPath;
-
- const SendIgnore(this.directoryPath);
-
- Future<Set<Glob>> get globs async {
- File ignoreFile = File('$directoryPath/$ignoreName');
- return makeGlobs(ignoreFile);
- }
-
- Future<Set<Glob>> makeGlobs(File ignoreFile) async {
- // if (!await ignoreFile.exists()) {
- // return {};
- // }
- final List<String> ignoreContents = await ignoreFile.readAsLines();
- final Set<Glob> ignoreGlobs = ignoreContents.map((line) => Glob('$directoryBaseName/$line')).toSet();
- return ignoreGlobs;
- }
-
- String get directoryBaseName {
- return p.basename(directoryPath);
- }
-}
diff --git a/app/lib/util/send_ignore.dart b/app/lib/util/send_ignore.dart
new file mode 100644
index 00000000..16c91c5e
--- /dev/null
+++ b/app/lib/util/send_ignore.dart
@@ -0,0 +1,36 @@
+import 'package:glob/glob.dart';
+
+// const _ignoreFileName = '.sendignore';
+
+class SendIgnore {
+ final List<Glob> _globs = [];
+
+ SendIgnore();
+
+ bool isIgnoreFile(String fileName) {
+ // TODO: Glob does not provide the same gitignore experience
+ return false;
+ // return fileName == _ignoreFileName;
+ }
+
+ void loadIgnoreContent({
+ required String? parentPath,
+ required List<String> ignoreContents,
+ }) {
+ _globs.addAll(ignoreContents.map((line) {
+ if (line.startsWith('/')) {
+ return Glob('$parentPath$line');
+ } else {
+ if (parentPath == null) {
+ return Glob(line);
+ } else {
+ return Glob('$parentPath/**/$line');
+ }
+ }
+ }));
+ }
+
+ bool isIgnored(String relativePath) {
+ return _globs.any((glob) => glob.matches('/$relativePath'));
+ }
+}