generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Adding ability to handle a custom rule directory (#132)
* 🐛 Adding ability to handle a custom rule directory Signed-off-by: Shawn Hurley <shawn@hurley.page> * when handeling files during copy ignore hidden/dot files Signed-off-by: Shawn Hurley <shawn@hurley.page> --------- Signed-off-by: Shawn Hurley <shawn@hurley.page>
- Loading branch information
1 parent
86942ac
commit 20af46f
Showing
3 changed files
with
129 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !windows && !windows | ||
// +build !windows,!windows | ||
|
||
package hiddenfile | ||
|
||
const dotCharacter = 46 | ||
|
||
func IsHidden(name string) (bool, error) { | ||
if name[0] == dotCharacter { | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package hiddenfile | ||
|
||
import ( | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
const dotCharacter = 46 | ||
|
||
// isHidden checks if a file is hidden on Windows. | ||
func IsHidden(name string) (bool, error) { | ||
// dotfiles also count as hidden (if you want) | ||
if name[0] == dotCharacter { | ||
return true, nil | ||
} | ||
|
||
absPath, err := filepath.Abs(name) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// Appending `\\?\` to the absolute path helps with | ||
// preventing 'Path Not Specified Error' when accessing | ||
// long paths and filenames | ||
// https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd | ||
pointer, err := syscall.UTF16PtrFromString(`\\?\` + absPath) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
attributes, err := syscall.GetFileAttributes(pointer) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil | ||
} |