googledrive icon indicating copy to clipboard operation
googledrive copied to clipboard

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

Open jakejh opened this issue 1 year ago • 3 comments

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!

jakejh avatar Sep 09 '24 14:09 jakejh

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.

jennybc avatar Sep 09 '24 21:09 jennybc

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 avatar Sep 10 '24 00:09 jakejh

@jennybc what do you think?

jakejh avatar Sep 21 '24 16:09 jakejh