Skip to content

watch .magnet files too#367

Merged
ikatson merged 2 commits intoikatson:mainfrom
FrancescElies:cesc/watch-magnets
Apr 27, 2025
Merged

watch .magnet files too#367
ikatson merged 2 commits intoikatson:mainfrom
FrancescElies:cesc/watch-magnets

Conversation

@FrancescElies
Copy link
Contributor

Currently only .torrent files are being considered when watching a folder.

This PR adds extends that functionality to .magnet files too.

None
}
})
.map(|(add_torrent, path)| {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of let _results = map().collect() (which allocates needlessly and creates an unused variable) you can use ether a for loop or for_each

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, done

.paths
.iter()
.filter_map(|path| match path.extension() {
Some(x) if x.to_str() == Some("torrent") => match read_and_validate_torrent(path) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would probably be a bit shorter an more efficient if you do

match path.extension().and_then(|e| e.to_str())? {
   "torrent" => ...,
   "magnet" => ...,
}

Copy link
Contributor Author

@FrancescElies FrancescElies Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, probably you don't want ? as if by any reason a file without extension would land in the watch folder you would return and not process the rest of files, wouldn't it?

Changed it to match path.extension().and_then(|e| e.to_str()) { ...}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's part of filter_map, the ? would only apply to the callback, not the outer function, so it should work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok learned something new, thanks, i will change that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I somehow I forgot that it was inside a closure, that's why, it returns from there.

Done

@FrancescElies FrancescElies force-pushed the cesc/watch-magnets branch 2 times, most recently from 3fc5caa to 0413ed7 Compare April 27, 2025 06:48
@ikatson ikatson merged commit 1307148 into ikatson:main Apr 27, 2025
5 checks passed
@FrancescElies FrancescElies deleted the cesc/watch-magnets branch April 27, 2025 14:49
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

Successfully merging this pull request may close these issues.

2 participants