Skip to content

Commit

Permalink
Handle long name tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Mar 10, 2024
1 parent 6c7c9fd commit 84ec384
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
7 changes: 6 additions & 1 deletion sources/lite_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,12 @@ int FuseHighLevelOps::vrmdir(const char* path, const fuse_context* ctx)
{
process_possible_long_name(path,
LongNameComponentAction::kDelete,
[&](std::string&& enc_path) { root_.remove_directory(enc_path); });
[&](std::string&& enc_path)
{
root_.remove_file_nothrow(
absl::StrCat(enc_path, "/", kLongNameTableFileName));
root_.remove_directory(enc_path);
});
return 0;
}
int FuseHighLevelOps::vchmod(const char* path, fuse_mode_t mode, const fuse_context* ctx)
Expand Down
64 changes: 54 additions & 10 deletions test/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def securefs_mount(
logging.info("Start mounting, command:\n%s", " ".join(command))
p = subprocess.Popen(
command,
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
if sys.platform == "win32"
else 0,
creationflags=(
subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == "win32" else 0
),
)
try:
for _ in range(300):
Expand Down Expand Up @@ -343,11 +343,53 @@ def unmount(cls):
cls.securefs_process = None

def test_long_name(self):
with self.assertRaises(EnvironmentError) as context:
os.mkdir(os.path.join(self.mount_point, "k" * 256))
self.fail("mkdir should fail")
os.mkdir(os.path.join(self.mount_point, "k" * 200))
os.mkdir(os.path.join(self.mount_point, "k" * 200, "✅" * 70))
with open(
os.path.join(self.mount_point, "k" * 200, "✅" * 70, "c" * 222), "w"
) as f:
f.write("test" * 70)
os.rename(
os.path.join(self.mount_point, "k" * 200, "✅" * 70, "c" * 222),
os.path.join(self.mount_point, "k" * 200, "✅" * 70, "d" * 222),
)
self.assertSetEqual(
set(os.listdir(os.path.join(self.mount_point, "k" * 200, "✅" * 70))),
{"d" * 222},
)
os.rename(
os.path.join(self.mount_point, "k" * 200, "✅" * 70, "d" * 222),
os.path.join(self.mount_point, "k" * 200, "🎈" * 70),
)
self.assertIn(
"🎈" * 70,
set(os.listdir(os.path.join(self.mount_point, "k" * 200))),
)
st = os.stat(os.path.join(self.mount_point, "k" * 200, "🎈" * 70))
self.assertEquals(st.st_size, 4 * 70)
os.rename(
os.path.join(self.mount_point, "k" * 200, "🎈" * 70),
os.path.join(self.mount_point, "k" * 200, "🎈" * 2),
)
if sys.platform != "win32":
self.assertEqual(context.exception.errno, errno.ENAMETOOLONG)
os.symlink(
"/bcd" * 20, os.path.join(self.mount_point, "k" * 200, "🔼" * 64)
)
self.assertEquals(
"/bcd" * 20,
os.readlink(os.path.join(self.mount_point, "k" * 200, "🔼" * 64)),
)
os.link(
os.path.join(self.mount_point, "k" * 200, "✅" * 70, "d" * 222),
os.path.join(self.mount_point, "k" * 200, "✅" * 60),
)
self.assertEquals(
os.stat(
os.path.join(self.mount_point, "k" * 200, "✅" * 60)
).st_nlink,
2,
)
shutil.rmtree(os.path.join(self.mount_point, "k" * 200))

if xattr is not None:

Expand Down Expand Up @@ -609,9 +651,11 @@ def test_regression(self):
os.path.join(reference_data_dir, data_dir),
mount_point,
password="abc" if mode & SecretInputMode.PASSWORD else None,
keyfile=os.path.join(reference_data_dir, "keyfile")
if mode & SecretInputMode.KEYFILE
else None,
keyfile=(
os.path.join(reference_data_dir, "keyfile")
if mode & SecretInputMode.KEYFILE
else None
),
config_filename=config_filename,
)
try:
Expand Down

0 comments on commit 84ec384

Please sign in to comment.