INNER CODE UNIT · Go

CreateMountpointSymlink

kimdre/doco-cd · cmd/doco-cd/main.go:65

func CreateMountpointSymlink(m container.MountPoint) error {
	// if source ends with `/` path.Dir will like remove `/`,
	// like `/data/dococd/` -> /data/dococd which is not what we want.
	source := filepath.Clean(m.Source)
	destination := filepath.Clean(m.Destination)

	if source == destination {
		return nil
	}

	symlinkParentDir := filepath.Dir(source)

	err := os.MkdirAll(symlinkParentDir, filesystem.PermDir)
	if err != nil {
		return fmt.Errorf("failed to create parent directory %s: %w", symlinkParentDir, err)
	}

	err = os.Symlink(destination, source)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…