Skip to content
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

Fix - accidentally omitted path Prefix for filePathMap files #283

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions vercel/data_source_prebuilt_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,21 @@ func processVCConfigFile(configPath, projectPath string, config *PrebuiltProject

// Process each file in the filePathMap
for filePath := range vcConfig.FilePathMap {
// Don't process if we've already added this file
if _, exists := config.Output[filePath]; exists {
continue
}

// Make sure the path is absolute relative to the project
absPath := filePath
if !filepath.IsAbs(absPath) {
absPath = filepath.Join(projectPath, absPath)
}

// Don't process if we've already added this file
if _, exists := config.Output[absPath]; exists {
continue
}

// Check if file exists
fileInfo, err := os.Lstat(absPath) // Use Lstat to not follow symlinks
if err != nil {
return fmt.Errorf("could not stat file %s referenced in filePathMap: %w", absPath, err)
return fmt.Errorf("could not stat file %s (%s) referenced in filePathMap: %w", filePath, absPath, err)
}

// Skip directories
Expand All @@ -309,24 +309,24 @@ func processVCConfigFile(configPath, projectPath string, config *PrebuiltProject
// It's a symlink - read the target path
linkTarget, err := os.Readlink(absPath)
if err != nil {
return fmt.Errorf("could not read symlink %s: %w", absPath, err)
return fmt.Errorf("could not read symlink %s (%s): %w", filePath, absPath, err)
}

// Hash the link target string (just like Vercel does)
targetData := []byte(linkTarget)
rawSha := sha1.Sum(targetData)
sha := hex.EncodeToString(rawSha[:])
config.Output[filePath] = fmt.Sprintf("%d~%s", len(targetData), sha)
config.Output[absPath] = fmt.Sprintf("%d~%s", len(targetData), sha)
} else {
// Regular file - read and hash its content
fileContent, err := os.ReadFile(absPath)
if err != nil {
return fmt.Errorf("could not read file %s referenced in filePathMap: %w", absPath, err)
return fmt.Errorf("could not read file %s (%s) referenced in filePathMap: %w", filePath, absPath, err)
}

rawSha := sha1.Sum(fileContent)
sha := hex.EncodeToString(rawSha[:])
config.Output[filePath] = fmt.Sprintf("%d~%s", len(fileContent), sha)
config.Output[absPath] = fmt.Sprintf("%d~%s", len(fileContent), sha)
}
}

Expand Down