Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.20.0 to 2.24.1. - [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.20.0...v2.24.1) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package plugintest
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func symlinkFile(src string, dest string) error {
|
|
err := os.Symlink(src, dest)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("unable to symlink %q to %q: %w", src, dest, err)
|
|
}
|
|
|
|
srcInfo, err := os.Stat(src)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("unable to stat %q: %w", src, err)
|
|
}
|
|
|
|
err = os.Chmod(dest, srcInfo.Mode())
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("unable to set %q permissions: %w", dest, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// symlinkDirectoriesOnly finds only the first-level child directories in srcDir
|
|
// and symlinks them into destDir.
|
|
// Unlike symlinkDir, this is done non-recursively in order to limit the number
|
|
// of file descriptors used.
|
|
func symlinkDirectoriesOnly(srcDir string, destDir string) error {
|
|
srcInfo, err := os.Stat(srcDir)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to stat source directory %q: %w", srcDir, err)
|
|
}
|
|
|
|
err = os.MkdirAll(destDir, srcInfo.Mode())
|
|
if err != nil {
|
|
return fmt.Errorf("unable to make destination directory %q: %w", destDir, err)
|
|
}
|
|
|
|
dirEntries, err := os.ReadDir(srcDir)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("unable to read source directory %q: %w", srcDir, err)
|
|
}
|
|
|
|
for _, dirEntry := range dirEntries {
|
|
if !dirEntry.IsDir() {
|
|
continue
|
|
}
|
|
|
|
srcPath := filepath.Join(srcDir, dirEntry.Name())
|
|
destPath := filepath.Join(destDir, dirEntry.Name())
|
|
err := symlinkFile(srcPath, destPath)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("unable to symlink directory %q to %q: %w", srcPath, destPath, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|