Улучшение обработки путей и добавление списка файлов
Go Build and Test / build-and-test (push) Successful in 29s
Go Build and Test / build-and-test (push) Successful in 29s
- Заменена filepath.Ext() на strings.HasSuffix() для корректной проверки расширений - Оптимизирована логика проверки исключаемых путей: - Упрощён pattern matching - Добавлена явная проверка префиксов путей - Улучшена обработка базовых имён файлов - Добавлен новый endpoint GET /backup: - Возвращает JSON-список файлов в директории бэкапов - Реализована фильтрация директорий
This commit is contained in:
1 parent
4639779116
commit
a1681ab58a
4 files changed
+235
-13
No files matched your search
+8
-12
@@ -167,11 +167,11 @@ func initialModel(src, dst string, excludePatterns []string) (*model, error) {
|
||||
} else {
|
||||
// Локальный файл
|
||||
if isDirectory {
|
||||
if filepath.Ext(targetPath) != ".tar.gz" {
|
||||
if !strings.HasSuffix(targetPath, ".tar.gz") {
|
||||
targetPath += ".tar.gz"
|
||||
}
|
||||
} else {
|
||||
if filepath.Ext(targetPath) != ".gz" {
|
||||
if !strings.HasSuffix(targetPath, ".gz") {
|
||||
targetPath += ".gz"
|
||||
}
|
||||
}
|
||||
@@ -303,23 +303,19 @@ func shouldExcludePath(path string, patterns []string) bool {
|
||||
cleanPath := filepath.Clean(path)
|
||||
|
||||
for _, pattern := range patterns {
|
||||
// Проверка полного совпадения
|
||||
if cleanPath == pattern {
|
||||
// Проверка полного совпадения пути
|
||||
if matched, _ := filepath.Match(pattern, cleanPath); matched {
|
||||
return true
|
||||
}
|
||||
|
||||
// Проверка префикса (исключение вложенных путей)
|
||||
// Проверка, что паттерн является префиксом пути (как каталог)
|
||||
if strings.HasPrefix(cleanPath, pattern+string(filepath.Separator)) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Проверка glob-паттернов
|
||||
if match, _ := filepath.Match(pattern, cleanPath); match {
|
||||
return true
|
||||
}
|
||||
|
||||
// Проверка на соответствие базовому имени
|
||||
if match, _ := filepath.Match(pattern, filepath.Base(cleanPath)); match {
|
||||
// Проверка базового имени файла/директории
|
||||
base := filepath.Base(cleanPath)
|
||||
if matched, _ := filepath.Match(pattern, base); matched {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user