Skip to content

fix: Windows Path Separator Compatibility Issue in getSortedSqlFileNames Function (#5150)#5151

Closed
2018yuli wants to merge 9 commits intoedgexfoundry:mainfrom
2018yuli:EF-5150
Closed

fix: Windows Path Separator Compatibility Issue in getSortedSqlFileNames Function (#5150)#5151
2018yuli wants to merge 9 commits intoedgexfoundry:mainfrom
2018yuli:EF-5150

Conversation

@2018yuli
Copy link

Problem:
While developing on Windows with EdgeX v4.0.0, I encountered an issue where PostgreSQL (pg) does not initialize properly. This issue is caused by the handling of file paths in the getSortedSqlFileNames function within pkg/db/postgres/utils.go.

The current implementation:

sqlFiles = append(sqlFiles, sqlFileName{order, filepath.Join(sqlFilesDir, fileName)})

assumes the Unix-style path separator, which causes issues on Windows systems.

Suggested Fix:
To ensure compatibility with Windows file path separators, I propose normalizing the path using filepath.ToSlash, as shown below:

func getSortedSqlFileNames(embedFiles embed.FS, sqlFilesDir string) ([]string, error) {
    ...
    sqlFiles = append(sqlFiles, sqlFileName{order, NormalizePath(sqlFilesDir, fileName)})
....
}

// NormalizePath normalizes file paths to be platform-independent.
func NormalizePath(baseDir, fileName string) string {
    return filepath.ToSlash(filepath.Join(baseDir, fileName))
}

Rationale:
Although EdgeX is primarily designed for Linux environments, this small fix will improve compatibility for developers working on Windows, making the project more accessible to a wider audience.

Related Issue:
This change is in response to the issue where PostgreSQL initialization fails on Windows due to path handling issues.

Testing Instructions:

  • I am not introducing a breaking change
  • I am not introducing a new dependency
  • I have added unit tests for the new feature or bug fix
  • I have fully tested this new feature or bug fix
level=INFO ts=2025-05-21T13:05:40.3388986+08:00 app=core-metadata source=message.go:58 msg="Service started in: 78.3767ms"

@cloudxxx8
Copy link
Member

you need to sign-off the commit to pass the DCO

// NormalizePath normalizes file paths to be platform-independent.
func NormalizePath(baseDir, fileName string) string {
return filepath.ToSlash(filepath.Join(baseDir, fileName))
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an empty line


// NormalizePath normalizes file paths to be platform-independent.
func NormalizePath(baseDir, fileName string) string {
return filepath.ToSlash(filepath.Join(baseDir, fileName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the go docs, filepath.Join should use the OS separator.
https://pkg.go.dev/path/filepath#Join

Windows is \ and Linux is /. If you wrap it with filepath.ToSlash, will it become always /?
Could this really solve the issue?

@2018yuli
Copy link
Author

2018yuli commented May 29, 2025 via email

@cloudxxx8
Copy link
Member

Yes, adding unit test could be very helpful.

Also,

  1. Please squash your commits with sign-off. DCO can be passed if there is any commits in this PR is not valid.
  2. Add an empty line to the end of the file.
  3. Run go fmt before committing the code. The Jenkins check is failed due to the gofmt check.
[2025-05-29T08:32:56.223Z] gofmt -l $(find . -type f -name '*.go'| grep -v "/vendor/")
[2025-05-29T08:32:56.223Z] ./internal/pkg/db/postgres/utils.go
[2025-05-29T08:32:56.223Z] [ "`gofmt -l $(find . -type f -name '*.go'| grep -v "/vendor/")`" = "" ]

judehung and others added 9 commits June 4, 2025 10:08
fixes edgexfoundry#5145

refactor the code to move the implementation of validateEvent from core-data to internal/pkg/utils for reuse.

Signed-off-by: Jude Hung <jude@iotechsys.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
…mes Function (edgexfoundry#5150)

converts a path to the format required for go embed by using '/' as the separator.

Signed-off-by: 2018yuli l898974766@outlook.com
Signed-off-by: l898974766 <l898974766@outlook.com>
…dgexfoundry#5155)

Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.13.3 to 4.13.4.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](labstack/echo@v4.13.3...v4.13.4)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-version: 4.13.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
…oundry#5149)

Bumps [github.com/jackc/pgx/v5](https://github.com/jackc/pgx) from 5.7.4 to 5.7.5.
- [Changelog](https://github.com/jackc/pgx/blob/master/CHANGELOG.md)
- [Commits](jackc/pgx@v5.7.4...v5.7.5)

---
updated-dependencies:
- dependency-name: github.com/jackc/pgx/v5
  dependency-version: 5.7.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
…edgexfoundry#5148)

Bumps [github.com/go-co-op/gocron/v2](https://github.com/go-co-op/gocron) from 2.16.1 to 2.16.2.
- [Release notes](https://github.com/go-co-op/gocron/releases)
- [Commits](go-co-op/gocron@v2.16.1...v2.16.2)

---
updated-dependencies:
- dependency-name: github.com/go-co-op/gocron/v2
  dependency-version: 2.16.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
Signed-off-by: yichun chou <yichunccc0830@gmail.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
Signed-off-by: yichun chou <yichunccc0830@gmail.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
Signed-off-by: yichun chou <yichunccc0830@gmail.com>
Signed-off-by: l898974766 <l898974766@outlook.com>
…mes Function (edgexfoundry#5150)

Signed-off-by: l898974766 <l898974766@outlook.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2025

@cloudxxx8 cloudxxx8 mentioned this pull request Jun 4, 2025
5 tasks
@cloudxxx8
Copy link
Member

@2018yuli you need to rebase the main branch to resolve the conflict
I just opened another PR based on your change. Could you review it?
#5170

@2018yuli
Copy link
Author

2018yuli commented Jun 4, 2025

Since cloudxxx8 has resolved the conflict and made the changes in PR 5170, I believe this PR can be closed. Thank you!

@2018yuli 2018yuli closed this Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants