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

SNOW-852665: Allow ~ in PUT/GET file path #1481

Merged
merged 1 commit into from
Jul 21, 2023
Merged

Conversation

sfc-gh-ext-simba-lb
Copy link
Contributor

Overview

SNOW-852665

PUT commands will fail if the source file path contains ~ even though this is accepted in folder names. This is because during parsing of the command, the driver filters out any ~ with the user home directory.

for (String path : filePathList) {
      // replace ~ with user home
      path = path.replace("~", systemGetProperty("user.home"));

So file path in the command "PUT 'file:///C:/snowflake~/test.txt' '@~' AUTO_COMPRESS=FALSE" would be parsed to "/C:/snowflakeC:\Users\user/test.txt"

GET commands will also fail if trying to download to a directory with ~ in the path name. This is because the driver checks if ~ is at the start of the command, then replaces with the user home directory. Afterwards it checks to see if the command still contains an ~ and will throw a PATH_NOT_DIRECTORY error.

      if (localLocation.startsWith("~")) {
        // replace ~ with user home
        localLocation = systemGetProperty("user.home") + localLocation.substring(1);
      }

      // it should not contain any ~ after the above replacement
      if (localLocation.contains("~")) {
        throw new SnowflakeSQLLoggedException(
            session,
            ErrorCode.PATH_NOT_DIRECTORY.getMessageCode(),
            SqlState.IO_ERROR,
            localLocation);
      }

External contributors - please answer these questions before submitting a pull request. Thanks!

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes PUT command fails with ~ in file name #1458
    https://github.com/snowflakedb/snowflake-sdks-drivers-issues-teamwork/issues/508

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Ensure that ~ is only replaced for PUT/GET if it's at the start of the command. Otherwise, allow ~ in folder directories.

Pre-review checklist

  • This change has passed precommit
  • I have reviewed code coverage report for my PR in (Sonarqube)

@sonarqubemergegate
Copy link

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb marked this pull request as ready for review July 20, 2023 14:13
@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb requested a review from a team as a code owner July 20, 2023 14:13
Copy link
Collaborator

@sfc-gh-igarish sfc-gh-igarish left a comment

Choose a reason for hiding this comment

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

LGTM

@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb merged commit 15a45ac into master Jul 21, 2023
12 checks passed
@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb deleted the SNOW-852665 branch July 21, 2023 14:09
@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PUT command fails with ~ in file name
2 participants