generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when handeling files during copy ignore hidden/dot files
Signed-off-by: Shawn Hurley <[email protected]>
- Loading branch information
1 parent
bf78f97
commit 588fe42
Showing
3 changed files
with
61 additions
and
0 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 | ||
} |