修复Windows'文件名太长的最简单方法'CI在此代码中测试失败?

问题描述 投票:0回答:1

我正在尝试解决this Windows filename issue

基本上,我们的CI作业失败,并且Windows出现“文件名太长”错误。

 warning: Could not stat path 'node_modules/data-validator/tests/data/data-examples/ds000247/sub-emptyroom/ses-18910512/meg/sub-emptyroom_ses-18910512_task-noise_run-01_meg.ds/sub-emptyroom_ses-18910512_task-noise_run-01_meg.acq': Filename too long

我已经阅读了Node的path模块的文档,这似乎是一种可能的解决方案。我还阅读了有关绕过MAX_PATH的Windows前缀(\\?\)的信息,但不知道如何以一种干净的方式实现它们。

代码库的此部分包含失败的测试。硬编码的路径(testDatasetPath)可能是问题的一部分。

function getDirectories(srcpath) {
  return fs.readdirSync(srcpath).filter(function(file) {
    return (
      file !== '.git' && fs.statSync(path.join(srcpath, file)).isDirectory()
    )
  })
}

var missing_session_files = //array of strings here

const dataDirectory = 'data-validator/tests/data/'

function createDatasetFileList(path) {
  const testDatasetPath = `${dataDirectory}${path}`
  if (!isNode) {
    return createFileList(testDatasetPath)
  } else {
    return testDatasetPath
  }
}

createFileList函数

function createFileList(dir) {
  const str = dir.substr(dir.lastIndexOf('/') + 1) + '$'
  const rootpath = dir.replace(new RegExp(str), '')
  const paths = getFilepaths(dir, [], rootpath)
  return paths.map(path => {
    return createFile(path, path.replace(rootpath, ''))
  })
}

tl; dr GitLab CI作业在Windows上失败,因为节点模块文件名变得太长。如何使此Node.js代码与操作系统无关?

node.js windows continuous-integration filenames node-modules
1个回答
0
投票

这是Windows环境中的已知错误,但是有修复程序。

如果使用的是基于NTFS的文件系统,则应该能够在中启用长路径

Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS

这在您刚刚链接的文档中也已指定,理论上应该可以。但是,路径实际上不应超过32位,

这会带来一些性能上的损失,但应该可以完成工作。

此外,您最好切换到更好的程序包或搜索替代方案。如果这是您自己的软件包,也许可以对其进行重组?

最后,如果这些都不起作用,请将项目文件夹直接移动到数据驱动器(C:\),这将减少其他嵌套和父文件夹。

这本质上是不好的,如果选择这样做,可能会在部署过程中遇到问题。

© www.soinside.com 2019 - 2024. All rights reserved.