-
Notifications
You must be signed in to change notification settings - Fork 640
Add some symlink support #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81f5564
419e3ae
36b86da
334b917
c138820
79bb2ee
8eadd86
157be25
b6a1da1
ee096d9
a8c56db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ import ( | |
"unicode/utf16" | ||
|
||
"github.com/microsoft/typescript-go/internal/tspath" | ||
"github.com/microsoft/typescript-go/internal/vfs" | ||
) | ||
|
||
type Common struct { | ||
RootFor func(root string) fs.FS | ||
RootFor func(root string) fs.FS | ||
Realpath func(path string) string | ||
} | ||
|
||
func RootLength(p string) int { | ||
|
@@ -60,16 +62,50 @@ func (vfs *Common) DirectoryExists(path string) bool { | |
return stat != nil && stat.IsDir() | ||
} | ||
|
||
func (vfs *Common) GetDirectories(path string) []string { | ||
entries := vfs.GetEntries(path) | ||
// TODO: should this really exist? ReadDir with manual filtering seems like a better idea. | ||
var dirs []string | ||
for _, entry := range entries { | ||
if entry.IsDir() { | ||
dirs = append(dirs, entry.Name()) | ||
func (vfs *Common) GetAccessibleEntries(path string) (result vfs.Entries) { | ||
addToResult := func(name string, mode fs.FileMode) (added bool) { | ||
if mode.IsDir() { | ||
result.Directories = append(result.Directories, name) | ||
return true | ||
} | ||
|
||
if mode.IsRegular() { | ||
result.Files = append(result.Files, name) | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
for _, entry := range vfs.GetEntries(path) { | ||
entryType := entry.Type() | ||
|
||
if addToResult(entry.Name(), entryType) { | ||
continue | ||
} | ||
|
||
if entryType&fs.ModeSymlink != 0 { | ||
// Easy case; UNIX-like system will clearly mark symlinks. | ||
if stat := vfs.stat(path + "/" + entry.Name()); stat != nil { | ||
addToResult(entry.Name(), stat.Mode()) | ||
} | ||
continue | ||
} | ||
|
||
if entryType&fs.ModeIrregular != 0 && vfs.Realpath != nil { | ||
// Could be a Windows junction. Try Realpath. | ||
// TODO(jakebailey): use syscall.Win32FileAttributeData instead | ||
fullPath := path + "/" + entry.Name() | ||
if realpath := vfs.Realpath(fullPath); fullPath != realpath { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this is not the fastest way to do this at all; but the code to do this correctly on Windows is pretty funky (see the intermediate state in #186, which I will bring back). Something I want to address in a follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference: 8998046 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (realpath however, is very very reliable!) |
||
if stat := vfs.stat(realpath); stat != nil { | ||
addToResult(entry.Name(), stat.Mode()) | ||
} | ||
} | ||
continue | ||
} | ||
} | ||
return dirs | ||
|
||
return result | ||
} | ||
|
||
func (vfs *Common) GetEntries(path string) []fs.DirEntry { | ||
|
Uh oh!
There was an error while loading. Please reload this page.