Compare commits

...

4 Commits

Author SHA1 Message Date
noctuum 8e23ba8b17 Reject an empty argument list in execute_lua
`lua.execute` with no arguments dereferenced `args.begin()`.
2026-09-28 11:36:53 +02:00
noctuum e656801cfa Limit tab completion to text before the cursor
`substr` takes a count, so the text after the cursor joined the prefix.
2026-09-28 11:00:25 +02:00
noctuum 9f6fd7994e Guard control in the main catch handlers
A start without HOME throws before control is constructed.
2026-09-28 10:46:13 +02:00
noctuum bb77aa644c Stop at max_active in scheduler.simple.removed
The limit was checked once, then every download was resumed.
2026-09-28 10:28:46 +02:00
7 changed files with 117 additions and 4 deletions
+5 -1
View File
@@ -28,9 +28,10 @@ cmd_scheduler_simple_removed(core::Download* download) {
control->core()->download_list()->pause(download);
core::View* viewActive = *control->view_manager()->find("active");
unsigned int numActive = viewActive->size_visible();
int64_t maxActive = rpc::call_command("scheduler.max_active", torrent::Object()).as_value();
if ((int64_t)viewActive->size_visible() >= maxActive)
if ((int64_t)numActive >= maxActive)
return torrent::Object();
// The 'started' view contains all the views we may choose amongst.
@@ -41,6 +42,9 @@ cmd_scheduler_simple_removed(core::Download* download) {
continue;
control->core()->download_list()->resume(*itr);
if ((int64_t)++numActive >= maxActive)
break;
}
return torrent::Object();
+1 -1
View File
@@ -100,7 +100,7 @@ PathInput::receive_do_complete() {
entry.s_name += '/';
}
range_type r = find_incomplete(dir, str().substr(dirEnd, get_pos()));
range_type r = find_incomplete(dir, str().substr(dirEnd, get_pos() - dirEnd));
if (r.first == r.second)
return; // Show some nice colors here.
+4 -2
View File
@@ -492,7 +492,8 @@ main(int argc, char** argv) {
control->cleanup();
} catch (torrent::internal_error& e) {
control->cleanup_exception();
if (control != nullptr)
control->cleanup_exception();
std::cout << "rtorrent: caught torrent::internal_error: "
<< e.what() << std::endl
@@ -505,7 +506,8 @@ main(int argc, char** argv) {
return -1;
} catch (std::exception& e) {
control->cleanup_exception();
if (control != nullptr)
control->cleanup_exception();
std::cout << "rtorrent: caught" << typeid(e).name() << " : " << e.what() << std::endl;
+4
View File
@@ -394,6 +394,10 @@ execute_lua(LuaEngine* engine, rpc::target_type target_type, torrent::Object con
switch (raw_args.type()) {
case torrent::Object::TYPE_LIST: {
const torrent::Object::list_type& args = raw_args.as_list();
if (args.empty())
throw torrent::input_error("Too few arguments.");
if (flags & LuaEngine::flag_string) {
check_lua_status(l_state, luaL_loadstring(l_state, args.begin()->as_string().c_str()));
} else {
+2
View File
@@ -69,6 +69,8 @@ rtorrent_Test_Src_SOURCES = $(rtorrent_Test_Common) \
src/test_command_string.h \
src/test_command_throttle.cc \
src/test_command_throttle.h \
src/test_input_path_input.cc \
src/test_input_path_input.h \
src/test_session_commit.cc \
src/test_session_commit.h \
src/test_session_storer.cc \
+77
View File
@@ -0,0 +1,77 @@
#include "config.h"
#include "test/src/test_input_path_input.h"
#include <cstdlib>
#include <sys/stat.h>
#include <unistd.h>
#include "input/path_input.h"
CPPUNIT_TEST_SUITE_REGISTRATION(TestInputPathInput);
void
TestInputPathInput::setUp() {
test_fixture::setUp();
char temp_dir[] = "/tmp/rtorrent_test_path_input_XXXXXX";
CPPUNIT_ASSERT(mkdtemp(temp_dir) != nullptr);
m_temp_dir = temp_dir;
CPPUNIT_ASSERT_EQUAL(0, mkdir((m_temp_dir + "/alpha").c_str(), 0755));
CPPUNIT_ASSERT_EQUAL(0, mkdir((m_temp_dir + "/alpha/beta").c_str(), 0755));
}
void
TestInputPathInput::tearDown() {
rmdir((m_temp_dir + "/alpha/beta").c_str());
rmdir((m_temp_dir + "/alpha").c_str());
rmdir(m_temp_dir.c_str());
test_fixture::tearDown();
}
// Tab at the end of the line completes the trailing component.
void
TestInputPathInput::test_complete_at_end() {
input::PathInput input;
input.str() = m_temp_dir + "/al";
input.set_pos(input.str().size());
CPPUNIT_ASSERT(input.pressed('\t'));
CPPUNIT_ASSERT_EQUAL(m_temp_dir + "/alpha/", input.str());
CPPUNIT_ASSERT_EQUAL(input.str().size(), input.get_pos());
}
// The same completion with the cursor left inside the line. Only the text up to
// the cursor selects the entry, and the rest of the line is discarded.
void
TestInputPathInput::test_complete_mid_line() {
input::PathInput input;
input.str() = m_temp_dir + "/alZZZ";
input.set_pos(m_temp_dir.size() + 3);
CPPUNIT_ASSERT(input.pressed('\t'));
CPPUNIT_ASSERT_EQUAL(m_temp_dir + "/alpha/", input.str());
CPPUNIT_ASSERT_EQUAL(input.str().size(), input.get_pos());
}
// A cursor resting on a separator keeps completing the component after it.
void
TestInputPathInput::test_cursor_on_separator() {
input::PathInput input;
input.str() = m_temp_dir + "/alpha/be";
input.set_pos(m_temp_dir.size() + 6);
CPPUNIT_ASSERT(input.pressed('\t'));
CPPUNIT_ASSERT_EQUAL(m_temp_dir + "/alpha/beta/", input.str());
CPPUNIT_ASSERT_EQUAL(input.str().size(), input.get_pos());
}
+24
View File
@@ -0,0 +1,24 @@
#include "test/helpers/test_fixture.h"
#include <string>
class TestInputPathInput : public test_fixture {
CPPUNIT_TEST_SUITE(TestInputPathInput);
CPPUNIT_TEST(test_complete_at_end);
CPPUNIT_TEST(test_complete_mid_line);
CPPUNIT_TEST(test_cursor_on_separator);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void test_complete_at_end();
void test_complete_mid_line();
void test_cursor_on_separator();
private:
std::string m_temp_dir;
};