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

Implement FolderFileWatcher #2336

Merged
merged 8 commits into from
Jul 21, 2022
Merged

Conversation

msftrubengu
Copy link
Contributor

@msftrubengu msftrubengu commented Jul 13, 2022

Implement wrapper around wil::unique_folder_change_reader to track new files created under a directory.

  • FolderFileWatcher: watch for new files on a given directory and an optional extension.

Also Visual Studio 2022 removing some extra spaces in vcproj files

Microsoft Reviewers: Open in CodeFlow

@msftrubengu msftrubengu requested a review from a team as a code owner July 13, 2022 19:58
@github-actions
Copy link

github-actions bot commented Jul 13, 2022

@check-spelling-bot Report

Unrecognized words, please review:

  • tmp
Previously acknowledged words that are now absent activatable amd Archs dsc efgh enr FWW Globals hackathon lww mytool OSVERSION Packagedx parametermap pathpaths symlink Uninitialize WDAG whatif wsb
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:msftrubengu/winget-cli.git repository
on the filewatcher branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/winget-cli/issues/comments/1183622677" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u

Comment on lines 57 to 58
#include <vector>
#include <unordered_set>
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

Suggested change
#include <vector>
#include <unordered_set>
#include <unordered_set>
#include <vector>

T U V #Resolved

namespace AppInstaller::Utility
{
// Watch for new/renamed files recursively in a given directory.
struct FolderFileWatcher
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

Isn't a FolderFileWatcher just a FolderFileExtensionWatcher with a null_opt optional extension to look for? #Resolved

FolderFileWatcher(FolderFileWatcher&&) = delete;
FolderFileWatcher& operator=(FolderFileWatcher&&) = delete;

void start();
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

Suggested change
void start();
void Start();

Uppercase function names. #Resolved

{
if (m_changeReader)
{
this->stop();
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

This seems unnecessary so long as Stop is implemented as delete m_changeReader which will happen at the end of the function anyway. #Resolved

private:
std::filesystem::path m_path;
std::string m_ext;
std::unordered_set<std::string> m_files;
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

Suggested change
std::unordered_set<std::string> m_files;
std::unordered_set<std::filesystem::path> m_files;

Why not this? #Resolved

// The file was renamed and this is the new name.
case wil::FolderChangeEvent::RenameNewName:
{
std::filesystem::path path = m_path / std::filesystem::path(filePath);
Copy link
Member

@JohnMcPMS JohnMcPMS Jul 13, 2022

Choose a reason for hiding this comment

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

I would think it fine to store just the relative path if that is what we are given. The user of this can recombine the two if they want. #Resolved

@ghost ghost added the Needs-Author-Feedback Issue needs attention from issue or PR author label Jul 13, 2022
@ghost ghost removed the Needs-Author-Feedback Issue needs attention from issue or PR author label Jul 15, 2022
@github-actions
Copy link

github-actions bot commented Jul 15, 2022

@check-spelling-bot Report

Unrecognized words, please review:

  • tmp
Previously acknowledged words that are now absent activatable amd Archs dsc efgh enr FWW Globals hackathon lww mytool OSVERSION Packagedx parametermap pathpaths symlink Uninitialize WDAG whatif wsb
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:msftrubengu/winget-cli.git repository
on the filewatcher branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/winget-cli/issues/comments/1185871241" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u

@msftrubengu msftrubengu merged commit baf0a49 into microsoft:master Jul 21, 2022
@msftrubengu msftrubengu deleted the filewatcher branch November 15, 2022 00:27
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