Files with no extension open as plain text

This is instead of asking the user.
This commit is contained in:
Allan Odgaard
2013-01-23 12:15:48 +01:00
parent 49bb52c812
commit 127ef7e9eb
2 changed files with 22 additions and 3 deletions

View File

@@ -108,6 +108,10 @@ static std::string find_file_type (std::string const& path, io::bytes_ptr const&
if(res == NULL_STR && effectivePath != NULL_STR)
res = settings_for_path(effectivePath, "attr.file.unknown-type " + pathAttributes, settingsDirectory).get(kSettingsFileTypeKey, NULL_STR);
// check if file has no extension, if so, treat it as plain text
if(res == NULL_STR && path::extension(effectivePath).empty())
res = "text.plain";
return res;
}

View File

@@ -125,6 +125,21 @@ public:
}
void test_file_type ()
{
test::jail_t jail;
path::set_content(jail.path("test.x-unknown"), "dummy");
stall_t* cb = new stall_t(NULL_STR, "x.test");
file::open_callback_ptr sharedPtr((file::open_callback_t*)cb);
file::open(jail.path("test.x-unknown"), osx::authorization_t(), sharedPtr);
cb->wait();
TS_ASSERT_EQUALS(cb->_error, false);
TS_ASSERT_EQUALS(cb->_file_type, "x.test");
TS_ASSERT_EQUALS(std::string(cb->_content->begin(), cb->_content->end()), "dummy");
}
void test_file_type_no_ext ()
{
test::jail_t jail;
path::set_content(jail.path("test"), "dummy");
@@ -135,18 +150,18 @@ public:
cb->wait();
TS_ASSERT_EQUALS(cb->_error, false);
TS_ASSERT_EQUALS(cb->_file_type, "x.test");
TS_ASSERT_EQUALS(cb->_file_type, "text.plain");
TS_ASSERT_EQUALS(std::string(cb->_content->begin(), cb->_content->end()), "dummy");
}
void test_file_type_failure ()
{
test::jail_t jail;
path::set_content(jail.path("test"), "dummy");
path::set_content(jail.path("test.x-unknown"), "dummy");
stall_t* cb = new stall_t;
file::open_callback_ptr sharedPtr((file::open_callback_t*)cb);
file::open(jail.path("test"), osx::authorization_t(), sharedPtr);
file::open(jail.path("test.x-unknown"), osx::authorization_t(), sharedPtr);
cb->wait();
TS_ASSERT_EQUALS(cb->_error, true);