@@ -121,19 +121,18 @@ std::vector<std::string> DatRepository::list_dats() {
121121void DatRepository::update_directory (const std::string &directory, const DatDBPtr &db) {
122122 auto dir = Dir (directory, true );
123123 std::unordered_set<std::string> files;
124- std::filesystem::path filepath;
125124
126- while ((filepath = dir. next ()) != " " ) {
125+ for ( const auto & entry: dir ) {
127126 try {
128- if (directory == filepath || name_type (filepath ) == NAME_IGNORE || !std::filesystem:: is_regular_file (filepath )) {
127+ if (directory == entry. path () || name_type (entry ) == NAME_IGNORE || !entry. is_regular_file ()) {
129128 continue ;
130129 }
131130
132- auto file = filepath .string ().substr (directory.size () + 1 );
131+ auto file = entry. path () .string ().substr (directory.size () + 1 );
133132
134133 struct stat st{};
135134
136- if (stat (filepath .c_str (), &st) < 0 ) {
135+ if (stat (entry. path () .c_str (), &st) < 0 ) {
137136 continue ;
138137 }
139138
@@ -152,14 +151,14 @@ void DatRepository::update_directory(const std::string &directory, const DatDBPt
152151 std::vector<DatDB::DatEntry> entries;
153152
154153 try {
155- auto zip_archive = zip_open (filepath .c_str (), 0 , nullptr );
154+ auto zip_archive = zip_open (entry. path () .c_str (), 0 , nullptr );
156155 if (zip_archive != nullptr ) {
157156 for (size_t index = 0 ; static_cast <int64_t >(index) < zip_get_num_entries (zip_archive, 0 ); index++) {
158157 try {
159158 auto entry_name = zip_get_name (zip_archive, index, 0 );
160159 auto output = OutputContextHeader ();
161160
162- auto source = std::make_shared<ParserSourceZip>(filepath , zip_archive, entry_name);
161+ auto source = std::make_shared<ParserSourceZip>(entry. path () , zip_archive, entry_name);
163162 auto parser_options = Parser::Options{{}, false };
164163 auto parser = Parser::create (source, {}, nullptr , &output, parser_options);
165164 if (parser) {
@@ -177,7 +176,7 @@ void DatRepository::update_directory(const std::string &directory, const DatDBPt
177176 else {
178177 auto output = OutputContextHeader ();
179178
180- auto source = std::make_shared<ParserSourceFile>(filepath );
179+ auto source = std::make_shared<ParserSourceFile>(entry. path () );
181180 auto parser_options = Parser::Options{{}, false };
182181 auto parser = Parser::create (source, {}, nullptr , &output, parser_options);
183182
@@ -195,7 +194,7 @@ void DatRepository::update_directory(const std::string &directory, const DatDBPt
195194 db->insert_file (file, st.st_mtime , st.st_size , entries);
196195 }
197196 catch (Exception &ex) {
198- output.error (" can't process '%s': %s" , filepath .c_str (), ex.what ());
197+ output.error (" can't process '%s': %s" , entry. path () .c_str (), ex.what ());
199198 }
200199 }
201200
0 commit comments