Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ function preprocessSymlinkDestination(path, type, linkPath) {
path = pathModule.resolve(linkPath, '..', path);
return pathModule.toNamespacedPath(path);
}
if (pathModule.isAbsolute(path)) {
// If the path is absolute, use the \\?\-prefix to enable long filenames
return pathModule.toNamespacedPath(path);
}
// Windows symlinks don't tolerate forward slashes.
return ('' + path).replace(/\//g, '\\');
}
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-fs-symlink-longpath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const tmpDir = tmpdir.path;
const longPath = path.join(...[tmpDir].concat(Array(30).fill('1234567890')));
fs.mkdirSync(longPath, { recursive: true });

// Test if we can have symlinks to files and folders with long filenames
const targetDirtectory = path.join(longPath, 'target-directory');
fs.mkdirSync(targetDirtectory);
const pathDirectory = path.join(tmpDir, 'new-directory');
fs.symlink(targetDirtectory, pathDirectory, 'dir', common.mustCall((err) => {
assert.ifError(err);
assert(fs.existsSync(pathDirectory));
}));

const targetFile = path.join(longPath, 'target-file');
fs.writeFileSync(targetFile, 'data');
const pathFile = path.join(tmpDir, 'new-file');
fs.symlink(targetFile, pathFile, common.mustCall((err) => {
assert.ifError(err);
assert(fs.existsSync(pathFile));
}));