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

drive_put may not account for type conversion when deciding whether file already exists #461

Open
jakejh opened this issue Sep 9, 2024 · 3 comments

Comments

@jakejh
Copy link

jakejh commented Sep 9, 2024

Hello, here's the behavior I'm observing in pseudocode.

# no file exists
drive_put(local_file_path, folder_url, file_name, type = 'document')
# now a google doc exists
drive_put(local_file_path, folder_url, file_name, type = 'document')
# desired behavior is update, but drive_put says no drive file exists
# now two google docs of the same name exist

Is this expected? Am I doing something wrong? Thanks!

@jennybc
Copy link
Member

jennybc commented Sep 9, 2024

I don't remember thinking about file type when working on this. What you describe above feels like a bug, though. It would be great to get an actual reprex (vs. pseudo-code), though.

@jakejh
Copy link
Author

jakejh commented Sep 10, 2024

library('googledrive')

# before running the code,
# create a file email.txt containing the email address for your google account,
# create a google drive folder and copy its url into folder-url.txt,
# create word files drive-file-1.docx and drive-file-2.docx

email = readLines('email.txt')
folder_url = readLines('folder-url.txt')
media1 = 'drive-file-1.docx'
media2 = 'drive-file-2.docx'

drive_auth(email = email)

# ok
drive_put(media1, folder_url, name = media1)
#> ℹ No pre-existing Drive file at this path. Calling `drive_upload()`.
#> Local file:
#> • 'drive-file-1.docx'
#> Uploaded into Drive file:
#> • 'drive-file-1.docx' <id: 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN->
#> With MIME type:
#> • 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
drive_ls(folder_url)
#> # A dribble: 1 × 3
#>   name              id                                drive_resource   
#>   <chr>             <drv_id>                          <list>           
#> 1 drive-file-1.docx 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN- <named list [42]>

drive_put(media1, folder_url, name = media1)
#> ℹ A Drive file already exists at this path. Calling `drive_update()`.
#> File updated:
#> • 'drive-file-1.docx' <id: 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN->
drive_ls(folder_url)
#> # A dribble: 1 × 3
#>   name              id                                drive_resource   
#>   <chr>             <drv_id>                          <list>           
#> 1 drive-file-1.docx 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN- <named list [42]>

# not ok
drive_put(media2, folder_url, type = 'document', name = media2)
#> ℹ No pre-existing Drive file at this path. Calling `drive_upload()`.
#> Local file:
#> • 'drive-file-2.docx'
#> Uploaded into Drive file:
#> • 'drive-file-2' <id: 1W5N5VzzW3HkgokARPtmHuh6wRAMfeTEteTLtxtXbCmA>
#> With MIME type:
#> • 'application/vnd.google-apps.document'
drive_ls(folder_url)
#> # A dribble: 2 × 3
#>   name              id                                           drive_resource
#>   <chr>             <drv_id>                                     <list>        
#> 1 drive-file-2      1W5N5VzzW3HkgokARPtmHuh6wRAMfeTEteTLtxtXbCmA <named list>  
#> 2 drive-file-1.docx 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN-            <named list>

drive_put(media2, folder_url, type = 'document', name = media2)
#> ℹ No pre-existing Drive file at this path. Calling `drive_upload()`.
#> Local file:
#> • 'drive-file-2.docx'
#> Uploaded into Drive file:
#> • 'drive-file-2' <id: 1uOxI-QOmzbzHe0t5S6qxCtul8YoZzA9Wa1fxXmfJe_8>
#> With MIME type:
#> • 'application/vnd.google-apps.document'
drive_ls(folder_url)
#> # A dribble: 3 × 3
#>   name              id                                           drive_resource
#>   <chr>             <drv_id>                                     <list>        
#> 1 drive-file-2      1uOxI-QOmzbzHe0t5S6qxCtul8YoZzA9Wa1fxXmfJe_8 <named list>  
#> 2 drive-file-2      1W5N5VzzW3HkgokARPtmHuh6wRAMfeTEteTLtxtXbCmA <named list>  
#> 3 drive-file-1.docx 1GXSI0LjSxE1pfIyDzwnHAc3ydlbrYmN-            <named list>

Created on 2024-09-09 with reprex v2.1.1

@jakejh
Copy link
Author

jakejh commented Sep 21, 2024

@jennybc what do you think?

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

No branches or pull requests

2 participants