mehrere Errors mit Boost Lib
-
Hallo zusammen,
ich möchte eine Funktion schreiben die einen Datenbankeintrag eines gelöschten Objektes(Datei oder verzeichnis) macht. Dazu habe ich die Methode write(). In der Datenbank soll aber auch die Größe der Datei oder des Verzeichnisses stehen. Dazu habe ich eine Methode getDirSize(). Jetzt wo ich die Funktion dafür fertig geschrieben habe bekomme ich sehr viele Errors. Leider war ich bisher nicht im stande, das selber zu lösen und bräuchte Hilfe. Kann mir wer ein paar Tipps geben?
void trashrm::Database::write(fs::path *objectPath, fs::path *oldPath) { //Get the Size of the Directory with all Files in if (fs::is_directory(objectPath)) { trashrm::Database::getDirSize(objectPath, size); } else if (fs::is_regular_file(objectPath)) { size = fs::file_size(objectPath); } /*char *sql = "INSERT INTO trashrm (FILENAME, FILESIZE, OLDPATH, DELETEDAT) " "VALUES (" + objectPath->filename() + ", ";*/ }void trashrm::Database::getDirSize(fs::path *objectPath, size_t *size) { for (fs::recursive_directory_iterator it(objectPath); it != fs::recursive_directory_iterator(); ++it) { if (fs::is_directory(*it)) { trashrm::Database::getDirSize(it, size); } else { size += fs::file_size(*it); } } }Fehlermeldung
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird betreten rm -f -r build/Debug rm -f dist/Debug/GNU-Linux-x86/trash_rm make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird verlassen CLEAN SUCCESSFUL (total time: 58ms) "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird betreten "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/trash_rm make[2]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird betreten mkdir -p build/Debug/GNU-Linux-x86 rm -f "build/Debug/GNU-Linux-x86/Database.o.d" g++ -c -g -I/usr/include/boost -MMD -MP -MF "build/Debug/GNU-Linux-x86/Database.o.d" -o build/Debug/GNU-Linux-x86/Database.o Database.cpp Database.cpp: In member function ‘void trashrm::Database::write(boost::filesystem::path*, boost::filesystem::path*)’: Database.cpp:60:36: error: no matching function for call to ‘is_directory(boost::filesystem::path*&)’ if (fs::is_directory(objectPath)) { ^ Database.cpp:60:36: note: candidates are: In file included from /usr/include/boost/filesystem.hpp:17:0, from Database.h:14, from Database.cpp:1: /usr/include/boost/filesystem/operations.hpp:176:15: note: bool boost::filesystem::is_directory(boost::filesystem::file_status) inline bool is_directory(file_status f) { return f.type() == directory_file; } ^ /usr/include/boost/filesystem/operations.hpp:176:15: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘boost::filesystem::file_status’ /usr/include/boost/filesystem/operations.hpp:294:8: note: bool boost::filesystem::is_directory(const boost::filesystem::path&) bool is_directory(const path& p) {return is_directory(detail::status(p));} ^ /usr/include/boost/filesystem/operations.hpp:294:8: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘const boost::filesystem::path&’ /usr/include/boost/filesystem/operations.hpp:296:8: note: bool boost::filesystem::is_directory(const boost::filesystem::path&, boost::system::error_code&) bool is_directory(const path& p, system::error_code& ec) ^ /usr/include/boost/filesystem/operations.hpp:296:8: note: candidate expects 2 arguments, 1 provided Database.cpp:63:44: error: no matching function for call to ‘is_regular_file(boost::filesystem::path*&)’ else if (fs::is_regular_file(objectPath)) { ^ Database.cpp:63:44: note: candidates are: In file included from /usr/include/boost/filesystem.hpp:17:0, from Database.h:14, from Database.cpp:1: /usr/include/boost/filesystem/operations.hpp:175:15: note: bool boost::filesystem::is_regular_file(boost::filesystem::file_status) inline bool is_regular_file(file_status f){ return f.type() == regular_file; } ^ /usr/include/boost/filesystem/operations.hpp:175:15: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘boost::filesystem::file_status’ /usr/include/boost/filesystem/operations.hpp:299:8: note: bool boost::filesystem::is_regular_file(const boost::filesystem::path&) bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));} ^ /usr/include/boost/filesystem/operations.hpp:299:8: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘const boost::filesystem::path&’ /usr/include/boost/filesystem/operations.hpp:301:8: note: bool boost::filesystem::is_regular_file(const boost::filesystem::path&, boost::system::error_code&) bool is_regular_file(const path& p, system::error_code& ec) ^ /usr/include/boost/filesystem/operations.hpp:301:8: note: candidate expects 2 arguments, 1 provided Database.cpp:64:40: error: no matching function for call to ‘file_size(boost::filesystem::path*&)’ size = fs::file_size(objectPath); ^ Database.cpp:64:40: note: candidates are: In file included from /usr/include/boost/filesystem.hpp:17:0, from Database.h:14, from Database.cpp:1: /usr/include/boost/filesystem/operations.hpp:447:20: note: uintmax_t boost::filesystem::file_size(const boost::filesystem::path&) boost::uintmax_t file_size(const path& p) {return detail::file_size(p);} ^ /usr/include/boost/filesystem/operations.hpp:447:20: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘const boost::filesystem::path&’ /usr/include/boost/filesystem/operations.hpp:450:20: note: uintmax_t boost::filesystem::file_size(const boost::filesystem::path&, boost::system::error_code&) boost::uintmax_t file_size(const path& p, system::error_code& ec) ^ /usr/include/boost/filesystem/operations.hpp:450:20: note: candidate expects 2 arguments, 1 provided Database.cpp: In member function ‘void trashrm::Database::getDirSize(boost::filesystem::path*, size_t*)’: Database.cpp:76:56: error: no matching function for call to ‘boost::filesystem::recursive_directory_iterator::recursive_directory_iterator(boost::filesystem::path*&)’ for (fs::recursive_directory_iterator it(objectPath); ^ Database.cpp:76:56: note: candidates are: In file included from /usr/include/boost/filesystem.hpp:17:0, from Database.h:14, from Database.cpp:1: /usr/include/boost/filesystem/operations.hpp:866:5: note: boost::filesystem::recursive_directory_iterator::recursive_directory_iterator(const boost::filesystem::path&, boost::system::error_code&) recursive_directory_iterator(const path& dir_path, ^ /usr/include/boost/filesystem/operations.hpp:866:5: note: candidate expects 2 arguments, 1 provided /usr/include/boost/filesystem/operations.hpp:855:5: note: boost::filesystem::recursive_directory_iterator::recursive_directory_iterator(const boost::filesystem::path&, boost::filesystem::symlink_option::enum_type, boost::system::error_code&) recursive_directory_iterator(const path& dir_path, ^ /usr/include/boost/filesystem/operations.hpp:855:5: note: candidate expects 3 arguments, 1 provided /usr/include/boost/filesystem/operations.hpp:845:14: note: boost::filesystem::recursive_directory_iterator::recursive_directory_iterator(const boost::filesystem::path&, boost::filesystem::symlink_option::enum_type) explicit recursive_directory_iterator(const path& dir_path, ^ /usr/include/boost/filesystem/operations.hpp:845:14: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘const boost::filesystem::path&’ /usr/include/boost/filesystem/operations.hpp:843:5: note: boost::filesystem::recursive_directory_iterator::recursive_directory_iterator() recursive_directory_iterator(){} // creates the "end" iterator ^ /usr/include/boost/filesystem/operations.hpp:843:5: note: candidate expects 0 arguments, 1 provided /usr/include/boost/filesystem/operations.hpp:835:9: note: boost::filesystem::recursive_directory_iterator::recursive_directory_iterator(const boost::filesystem::recursive_directory_iterator&) class recursive_directory_iterator ^ /usr/include/boost/filesystem/operations.hpp:835:9: note: no known conversion for argument 1 from ‘boost::filesystem::path*’ to ‘const boost::filesystem::recursive_directory_iterator&’ Database.cpp:79:51: error: no matching function for call to ‘trashrm::Database::getDirSize(boost::filesystem::recursive_directory_iterator&, size_t*&)’ trashrm::Database::getDirSize(it, size); ^ Database.cpp:79:51: note: candidate is: Database.cpp:75:6: note: void trashrm::Database::getDirSize(boost::filesystem::path*, size_t*) void trashrm::Database::getDirSize(fs::path *objectPath, size_t *size) { ^ Database.cpp:75:6: note: no known conversion for argument 1 from ‘boost::filesystem::recursive_directory_iterator’ to ‘boost::filesystem::path*’ make[2]: *** [build/Debug/GNU-Linux-x86/Database.o] Fehler 1 make[2]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird verlassen make[1]: *** [.build-conf] Fehler 2 make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird verlassen make: *** [.build-impl] Fehler 2 BUILD FAILED (exit value 2, total time: 488ms)Ich verstehe nicht wieso er zB bei der ersten Meldung mit is_directory nicht anfangen kann. Hab das im Projekt schon mehrmals ohne Probleme verwendet.
-
Du hast Pointer auf path, die Funktionen wollen eine Reference.
-
hab das Problem jetzt gelöst. Bin total durcheinander gekommen mit Pointern und References. Hab aber jetzt das nächste Problem. Kann da bitte nochmal kurz einer drüber gucken?
meine write Methode
void trashrm::Database::write(fs::path &objectPath, fs::path &oldPath) { //Get the Size of the Directory with all Files in if (fs::is_directory(objectPath)) { trashrm::Database::getDirSize(objectPath); } else if (fs::is_regular_file(objectPath)) { size = (size_t*)fs::file_size(objectPath); } char sql[] = "INSERT INTO trashrm (FILENAME, FILESIZE, OLDPATH, DELETEDAT) " "VALUES (" + objectPath.filename().string() + ", " + boost::lexical_cast<std::string>(size) + ", " + fs::canonical(oldPath).string() + ", NOW());"; }der neue Error
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird betreten "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/trash_rm make[2]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird betreten mkdir -p build/Debug/GNU-Linux-x86 rm -f "build/Debug/GNU-Linux-x86/Database.o.d" g++ -c -g -I/usr/include/boost -MMD -MP -MF "build/Debug/GNU-Linux-x86/Database.o.d" -o build/Debug/GNU-Linux-x86/Database.o Database.cpp Database.cpp: In member function ‘void trashrm::Database::write(boost::filesystem::path&, boost::filesystem::path&)’: Database.cpp:69:57: error: initializer fails to determine size of ‘sql’ + fs::canonical(oldPath).string() + ", NOW());"; ^ Database.cpp:69:57: error: array must be initialized with a brace-enclosed initializer make[2]: *** [build/Debug/GNU-Linux-x86/Database.o] Fehler 1 make[2]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird verlassen make[1]: *** [.build-conf] Fehler 2 make[1]: Verzeichnis »/home/benni/NetBeansProjects/Trash RM« wird verlassen make: *** [.build-impl] Fehler 2 BUILD FAILED (exit value 2, total time: 867ms)
-
Dein SQL Query ist kein String Literal mehr, daher kannst du damit kein char Array initialisieren. Wenn du aus der sql Variable einen
std::stringmachst sollte es gehen.
-
das Problem ist das Sqlite in seiner Funktion sqlite3_exec einen char parameter erwartet und keinen string.
edit: habs jetzt so gelöst, finde ich aber sehr unschön.
std::string sqll = "INSERT INTO trashrm (FILENAME, FILESIZE, OLDPATH, DELETEDAT) " "VALUES (" + objectPath.filename().string() + ", " + boost::lexical_cast<std::string>(size) + ", " + fs::canonical(oldPath).string() + ", NOW());"; char *sql = new char(sqll.length()); strcpy(sql, sqll.c_str());
-
Lern erst mal richtig Programmieren.
-
Bennisen schrieb:
das Problem ist das Sqlite in seiner Funktion sqlite3_exec einen char parameter erwartet und keinen string
Dafür gibts doch die
.c_str()Memberfunktion, die du ja offensichtlich kennst. Du kannst einfachsqlite3_exec(sqll.c_str());schreiben (+irgendwelche andere Parameter).
-
Hatte ich noch garnicht probiert, aber es funktioniert. danke
