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

Do not create parent directory if it is root #2120

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions common/writeThoughFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,28 @@ const PreserveOwnerDefault = true
var RootDriveRegex = regexp.MustCompile(`(?i)(^[A-Z]:\/?$)`)
var RootShareRegex = regexp.MustCompile(`(^\/\/[^\/]*\/?$)`)

func isRootPath(s string) bool {
shortParentDir := strings.ReplaceAll(ToShortPath(s), OS_PATH_SEPARATOR, AZCOPY_PATH_SEPARATOR_STRING)
return RootDriveRegex.MatchString(shortParentDir) ||
RootShareRegex.MatchString(shortParentDir) ||
strings.EqualFold(shortParentDir, "/")
}


func CreateParentDirectoryIfNotExist(destinationPath string, tracker FolderCreationTracker) error {
// find the parent directory
directory := destinationPath[:strings.LastIndex(destinationPath, DeterminePathSeparator(destinationPath))]
// If we're pointing at the root of a drive, don't try because it won't work.
if isRootPath(destinationPath) {
return nil
}

lastIndex := strings.LastIndex(destinationPath, DeterminePathSeparator(destinationPath))
directory := destinationPath[:lastIndex]
return CreateDirectoryIfNotExist(directory, tracker)
}

func CreateDirectoryIfNotExist(directory string, tracker FolderCreationTracker) error {
// If we're pointing at the root of a drive, don't try because it won't work.
if shortParentDir := strings.ReplaceAll(ToShortPath(directory), OS_PATH_SEPARATOR, AZCOPY_PATH_SEPARATOR_STRING); RootDriveRegex.MatchString(shortParentDir) || RootShareRegex.MatchString(shortParentDir) || strings.EqualFold(shortParentDir, "/") {
if isRootPath(directory) {
return nil
}

Expand Down
23 changes: 23 additions & 0 deletions testSuite/scripts/test_blob_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ def test_download_1kb_blob_to_null(self):
dst = os.devnull
result = util.Command("copy").add_arguments(src).add_arguments(dst).add_flags("log-level", "info")

def test_download_1kb_blob_to_root(self):
Copy link
Member

Choose a reason for hiding this comment

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

I thought we are trying to avoid adding tests to the testSuite? Shouldn't we add new tests to e2e tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

The current infra either in e2e or cmd suite does not allow to create custom destination path. There would always be a temporary directory created for local path.

Copy link
Member

Choose a reason for hiding this comment

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

can you add this as a comment in this test?

Copy link
Member

Choose a reason for hiding this comment

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

Why don't we add this functionality then? It doesn't sound too complicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

It creates a lot of noise in E2E. The location where we create a temp directory is specific to resourceLocal. Which is at least 3 layers down the E2E interface to write tests. Either propagate a variable here - which would mean all the testcases would now take a new variable to say this is a special path to root, or some kind of env or hack so that we dont create a temp directory.

The bug is particular to download path, and does not need to be tested with the all combinations of flags/fromTos in E2E. It is cleaner to do in python suite.

# create file of size 1kb
filename = "test_1kb_blob_upload_download_null.txt"
file_path = util.create_test_file(filename, 1024)

# upload 1kb using azcopy
src = file_path
dst = util.test_container_url
result = util.Command("copy").add_arguments(src).add_arguments(dst). \
add_flags("log-level", "info").execute_azcopy_copy_command()
self.assertTrue(result)

# verify the uploaded blob
resource_url = util.get_resource_sas(filename)
result = util.Command("testBlob").add_arguments(file_path).add_arguments(resource_url).execute_azcopy_verify()
self.assertTrue(result)

# downloading the uploaded blob to devnull
# note we have no tests to verify the success of check-md5. TODO: remove this when fault induction is introduced
src = util.get_resource_sas(filename)
dst = "/"
result = util.Command("copy").add_arguments(src).add_arguments(dst).add_flags("log-level", "info")

# test_download_1kb_blob verifies the download of 1Kb blob using azcopy.
def test_download_1kb_blob(self):
# create file of size 1KB.
Expand Down