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

Ability to set custom path for DownloadFile & InputFileGenerated #379

Open
vkryl opened this issue Oct 3, 2018 · 11 comments
Open

Ability to set custom path for DownloadFile & InputFileGenerated #379

vkryl opened this issue Oct 3, 2018 · 11 comments

Comments

@vkryl
Copy link
Contributor

vkryl commented Oct 3, 2018

@Nullable String path in DownloadFile would allow implementing features such as:

  • Download folder setting (without need in restarting & moving all already downloaded files to a new directory manually by client)
  • Client would be able to control directories' names
  • Save As...

Probably more.

@Nullable String path in InputFileGenerated would, for example, allow saving generated media directly to the gallery.

Currently clients have two options: copying generated file after generation finish (which would double disk space usage per file) & moving generated file after generation finish (which probably? would waste data usage, if user tries to upload same generated file again later).

@levlam
Copy link
Contributor

levlam commented Oct 4, 2018

It will make impossible for TDLib to manage these files as part of application cache. They will never be deleted by optimizeStorage and will not be returned by getStorageStatistics.

It also can introduce a lot of security vulnerabilities, allowing to rewrite critical for application files and exploiting some file system/file access vulnerabilities.

@vkryl
Copy link
Contributor Author

vkryl commented Oct 21, 2018

The fact that they won't be able to be detected by storage statistics is not so critical, as user will be able to remove such files manually from gallery.

However, why it's not possible to add something like String[] additionalScanFolders to storage statistics / optimization requests? The fact that such files won't be removed by automatic check (e.g. Keep Media setting) is in fact good, as they should not be deleted.

Also I didn't understand the part about vulnerabilities. Such option is supposed to be used only for media, which are usually not opened by clients themselves (except for photos).

In case of secret chats / thumbnails / other stuff TDLib could easily ignore this parameter for security reasons.

@levlam
Copy link
Contributor

levlam commented Oct 21, 2018

Do you expect that TDLib will clean user's gallery if it is specified in additionalScanFolders? It's too dangerous to delete any file outside TDLib's file directory, because the file may be needed by user. It makes additionalScanFolders parameter useless.

There are a lot of vulnerabilities, which can allow intruder to rewrite system file/app database if it can choose name of a file to create in the file system. TDLib protects from such vulnerabilities by restricting list of folders in which files can be created and by heavily limiting number of allowed characters in file names. There is a cleanFileName synchronous method, which allows application to repeat TDLib's logic, but it is yet hard to use right.

@vkryl
Copy link
Contributor Author

vkryl commented Oct 21, 2018

No, I don't, but there are many other types of files.

It's not necessarily should allow choosing output file name, if it would allow just choosing custom folder (controlled by client itself) it would be enough to implement many requested features, such as saving downloaded photos and videos to gallery without duplicating them / exposing all other types of media to the public directory.

@x2bool
Copy link

x2bool commented Jan 14, 2019

Any ideas how to implement downloading documents into custom location like "Downloads"?

@zevlg
Copy link

zevlg commented Jan 14, 2019

Any ideas how to implement downloading documents into custom location like "Downloads"?

Client might create hardlink (in some custom dir) to the downloaded file, so when tdlib optimizes storage the file won’t be removed from filesystem

@zevlg
Copy link

zevlg commented Jan 14, 2019

Drawback of hardlink is that in must belong to same disk volume

@levlam
Copy link
Contributor

levlam commented Jan 14, 2019

Creating a hardlink or copying the file after it was downloaded is a good idea for now. Currently, there is no way to ask TDLib to create a file outside of database/files directory.

@laitianxu
Copy link

hi Use TdApi.DownloadFile to download images to directory photos, Under what circumstances are images in the directory deleted,Is it the capacity of photos or the number of images,Is there any way to keep the image from being deleted

@levlam
Copy link
Contributor

levlam commented Sep 27, 2019

@laitianxu If you pass setTdlibParameters.useStorageOptimizer=false and never explicitly call optimizeStorage, then files are deleted only when the corresponding message is permanently deleted.

@rishabhhgupta
Copy link

hardlink

where is database/files i check in my phone and Device File Explorer but I didn't find the download
location

zevlg added a commit to zevlg/telega.el that referenced this issue Nov 28, 2023
- [fix] Critical fix, `telega-tdlib--chat-list` might corrupt due to
  `telega--searchMessages` which could modify list by side-effect

- [fix] Use new reply-to API in `telega-chatbuf--input-draft-update`

- [enh] Use custom `filter-buffer-substring-function` in the chatbufs.
  To cut off `line-prefix` and `wrap-prefix` text properties from
  copied text

- [enh] Push just edited message into messages ring, so `M-g x` could be
  used to jump to just edited message.
  Fixes https://t.me/emacs_telega/43244

- [enh] Use `OK-IF-ALREADY-EXISTS` argument to `copy-file`
  Fixes tdlib/td#379

Version -> 0.8.216
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

7 participants
@zevlg @x2bool @vkryl @levlam @laitianxu @rishabhhgupta and others