Просмотр исходного кода

Merge pull request #9797 from overleaf/bg-ignore-synctex-files

Improve handling of ignored files

GitOrigin-RevId: c202a4262297408e9bd1d7af9697c2d7dae17cb0
Brian Gough 3 лет назад
Родитель
Сommit
f27e0f124b

+ 22 - 8
services/web/app/src/Features/Uploads/FileTypeManager.js

@@ -5,15 +5,19 @@ const { promisifyAll } = require('../../util/promises')
 const Settings = require('@overleaf/settings')
 const Settings = require('@overleaf/settings')
 
 
 const FileTypeManager = {
 const FileTypeManager = {
-  TEXT_EXTENSIONS: Settings.textExtensions.map(ext => `.${ext}`),
+  TEXT_EXTENSIONS: new Set(Settings.textExtensions.map(ext => `.${ext}`)),
 
 
-  IGNORE_EXTENSIONS: [
+  IGNORE_EXTENSIONS: new Set([
     '.dvi',
     '.dvi',
     '.aux',
     '.aux',
     '.log',
     '.log',
     '.toc',
     '.toc',
     '.out',
     '.out',
     '.pdfsync',
     '.pdfsync',
+    '.synctex', // synctex.gz is handled by the .gz extension
+    '.synctex(busy)',
+    '.fdb_latexmk',
+    '.fls',
     // Index and glossary files
     // Index and glossary files
     '.nlo',
     '.nlo',
     '.ind',
     '.ind',
@@ -27,9 +31,12 @@ const FileTypeManager = {
     '.doc',
     '.doc',
     '.docx',
     '.docx',
     '.gz',
     '.gz',
-  ],
+    '.swp',
+  ]),
 
 
-  IGNORE_FILENAMES: ['__MACOSX', '.git', '.gitignore'],
+  IGNORE_FILENAMES: new Set(['.gitignore']),
+
+  IGNORE_FOLDERS: new Set(['__MACOSX', '.git', '.texpadtmp', '.R']),
 
 
   MAX_TEXT_FILE_SIZE: 1 * 1024 * 1024, // 1 MB
   MAX_TEXT_FILE_SIZE: 1 * 1024 * 1024, // 1 MB
 
 
@@ -116,15 +123,22 @@ const FileTypeManager = {
   shouldIgnore(path, callback) {
   shouldIgnore(path, callback) {
     const basename = Path.basename(path)
     const basename = Path.basename(path)
     const extension = Path.extname(basename).toLowerCase()
     const extension = Path.extname(basename).toLowerCase()
+    const folders = path.split('/')
     let ignore = false
     let ignore = false
     if (basename.startsWith('.') && basename !== '.latexmkrc') {
     if (basename.startsWith('.') && basename !== '.latexmkrc') {
       ignore = true
       ignore = true
     }
     }
-    if (FileTypeManager.IGNORE_EXTENSIONS.includes(extension)) {
+    if (FileTypeManager.IGNORE_EXTENSIONS.has(extension)) {
       ignore = true
       ignore = true
-    }
-    if (FileTypeManager.IGNORE_FILENAMES.includes(basename)) {
+    } else if (FileTypeManager.IGNORE_FILENAMES.has(basename)) {
       ignore = true
       ignore = true
+    } else {
+      for (const folder of folders) {
+        if (FileTypeManager.IGNORE_FOLDERS.has(folder)) {
+          ignore = true
+          break
+        }
+      }
     }
     }
     callback(null, ignore)
     callback(null, ignore)
   },
   },
@@ -133,7 +147,7 @@ const FileTypeManager = {
 function _isTextFilename(filename) {
 function _isTextFilename(filename) {
   const extension = Path.extname(filename).toLowerCase()
   const extension = Path.extname(filename).toLowerCase()
   return (
   return (
-    FileTypeManager.TEXT_EXTENSIONS.includes(extension) ||
+    FileTypeManager.TEXT_EXTENSIONS.has(extension) ||
     filename.match(/^(\.)?latexmkrc$/)
     filename.match(/^(\.)?latexmkrc$/)
   )
   )
 }
 }

+ 30 - 0
services/web/test/unit/src/Uploads/FileTypeManagerTests.js

@@ -351,6 +351,16 @@ describe('FileTypeManager', function () {
       })
       })
     })
     })
 
 
+    it('should ignore .git directories and contained files', function (done) {
+      this.FileTypeManager.shouldIgnore('path/.git/info', (err, ignore) => {
+        if (err) {
+          return done(err)
+        }
+        ignore.should.equal(true)
+        done()
+      })
+    })
+
     it('should not ignore .latexmkrc dotfile', function (done) {
     it('should not ignore .latexmkrc dotfile', function (done) {
       this.FileTypeManager.shouldIgnore('path/.latexmkrc', (err, ignore) => {
       this.FileTypeManager.shouldIgnore('path/.latexmkrc', (err, ignore) => {
         if (err) {
         if (err) {
@@ -371,6 +381,26 @@ describe('FileTypeManager', function () {
       })
       })
     })
     })
 
 
+    it('should ignore synctex files', function (done) {
+      this.FileTypeManager.shouldIgnore('file.synctex', (err, ignore) => {
+        if (err) {
+          return done(err)
+        }
+        ignore.should.equal(true)
+        done()
+      })
+    })
+
+    it('should ignore synctex(busy) files', function (done) {
+      this.FileTypeManager.shouldIgnore('file.synctex(busy)', (err, ignore) => {
+        if (err) {
+          return done(err)
+        }
+        ignore.should.equal(true)
+        done()
+      })
+    })
+
     it('should not ignore .tex files', function (done) {
     it('should not ignore .tex files', function (done) {
       this.FileTypeManager.shouldIgnore('file.tex', (err, ignore) => {
       this.FileTypeManager.shouldIgnore('file.tex', (err, ignore) => {
         if (err) {
         if (err) {