-
Notifications
You must be signed in to change notification settings - Fork 2
Implement basic operations #13
Implement basic operations #13
Conversation
storage.go
Outdated
tmp := strings.Split(path, "/") | ||
for i := 0; i < len(tmp); i++ { | ||
if i == 0 { | ||
fileId, err = s.createDir(ctx, tmp[0], "root") | ||
} else if i != len(tmp)-1 { | ||
fileId, err = s.createDir(ctx, tmp[i], fileId) | ||
} else { | ||
file := &drive.File{Name: tmp[i]} | ||
_, err = s.service.Files.Create(file).Context(ctx).Media(r).Do() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I have misunderstood something. If user calls Write("a/b/c.txt")
, but directory a/b
is not exist, should we create them for user? If not, these lines could be simply deleted. Ping @Xuanwo to have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user calls
Write("a/b/c.txt")
, but directorya/b
is not exist, should we create them for user?
Yes, we need to create dirs for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will do a quick fix for this.
I'm really sorry about the messy code but I have to rewrite most of them, and I have no idea why the tests failed. BTW, the cache support will in the next PR. |
To implement
LGTM |
storage.go
Outdated
// pathToId converts path to fileId, as we talked in RFC-14. | ||
// Ref: https://github.com/beyondstorage/go-service-gdrive/blob/master/docs/rfcs/14-gdrive-for-go-storage-design.md | ||
// If success, we will return the fileId of the path we passing, and nil for sure. | ||
// But if the path is not exist, we will return an empty string and error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will send API in pathToId
, how will we handle the API error here?
How about adding a rule that:
err
represents the error handled inpathToId
fileId
represents the results:fileId
empty means the path is not exist, otherwise it's thefileId
of input path.
storage.go
Outdated
pathUnits := strings.Split(absPath, "/") | ||
fileId = "root" | ||
// Traverse the whole path, break the loop if we fails at one search | ||
for i := 0; i < len(pathUnits); i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using for _, v := range pathUnits
here?
storage.go
Outdated
fileId = "root" | ||
// Traverse the whole path, break the loop if we fails at one search | ||
for i := 0; i < len(pathUnits); i++ { | ||
fileId, err = s.searchContentInDir(ctx, fileId, pathUnits[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check error here, we need to break the for loop ASAP.
storage.go
Outdated
@@ -2,35 +2,251 @@ package gdrive | |||
|
|||
import ( | |||
"context" | |||
"fmt" | |||
"github.com/beyondstorage/go-storage/v4/services" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's format the imports.
- stdlib
- external libs
- self libs
storage.go
Outdated
) | ||
|
||
const DirectoryMimeType = "application/vnd.google-apps.folder" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't export unless we really need it.
Great job! |
This is the second PR of my work. It intends to finish tasks below:
General tracking issue: #6