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

Truncate long filenames #5116

Merged
merged 1 commit into from Oct 26, 2021
Merged

Conversation

vasantvohra
Copy link
Contributor

Users occasionally upload a file with a very lengthy name (>250) in the file field of the registration form; Mac and most OS allow up to 255 characters, but our servers return the error [Errno 36] File name too long.

Traceback:

File "/nas/indico.un/v2/indico-un/indico/indico/core/storage/models.py", line 208, in save
    self.storage_file_id, self.md5 = self.storage.save(path, self.content_type, self.filename, data)
  File "/nas/indico.un/v2/indico-un/indico/indico/core/storage/backend.py", line 252, in save
    with open(filepath, 'wb') as f:
StorageError: Could not save "event/1000135/registrations/5552/614104/102009-1633527965-AREMDCAM_AND_AUAG-CAMEROON-LETTER_OF_NOMINATIONS_ASSIGNMENT__RECOMMENDATION_FOR_ACCREDITATION_TO_THE7th_SESSION_OF_THE_MOP_TO_THE_AARHUS_CONVENTION_4TH_SESSION_OF_THE_MOPP_ON_PRTRs_THEIR_JHLS_AND_ASSOCIATED_MEETINGS_18-22_OCTOBER_IN_SWITZERLAN.pdf": 

[Errno 36] File name too long: u'/indico.un/v2/data/archive/event/1000135/registrations/5552/614104/102009-1633527965-AREMDCAM_AND_AUAG-CAMEROON-LETTER_OF_NOMINATIONS_ASSIGNMENT__RECOMMENDATION_FOR_ACCREDITATION_TO_THE7th_SESSION_OF_THE_MOP_TO_THE_AARHUS_CONVENTION_4TH_SESSION_OF_THE_MOPP_ON_PRTRs_THEIR_JHLS_AND_ASSOCIATED_MEETINGS_18-22_OCTOBER_IN_SWITZERLAN.pdf'

@vasantvohra
Copy link
Contributor Author

vasantvohra commented Oct 20, 2021

May I get a review here? I've tested this PR on v3

@ThiefMaster
Copy link
Member

Looks fine, but I'd like to have a unit test for this. I think we have a test for the function itself, so adding a new case covering this might be enough.

@vasantvohra
Copy link
Contributor Author

Hello, Morning, I added a test case to cover this. But, it is a hardcoded string of length 255, let me know if you'd prefer something autogenerated.

indico/util/fs.py Outdated Show resolved Hide resolved
indico/util/fs_test.py Outdated Show resolved Hide resolved
indico/util/fs.py Outdated Show resolved Hide resolved
@vasantvohra vasantvohra force-pushed the Truncate_filename branch 3 times, most recently from 93cde8a to b201c08 Compare October 21, 2021 11:25
@ThiefMaster ThiefMaster enabled auto-merge (rebase) October 26, 2021 09:44
@ThiefMaster ThiefMaster added this to the v3.0 milestone Oct 26, 2021
@ThiefMaster ThiefMaster added this to In progress in Release 3.0 via automation Oct 26, 2021
@ThiefMaster ThiefMaster merged commit da84ade into indico:3.0.x Oct 26, 2021
Release 3.0 automation moved this from In progress to Done Oct 26, 2021
@ThiefMaster ThiefMaster deleted the Truncate_filename branch October 26, 2021 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Release 3.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants