Reject write operations with expect_gen=0

Per PROTOCOL.txt specification, WRITE operations must provide a valid
generation counter and cannot use expect_gen=0 (unlike other operations).

This ensures the client has retrieved the file's metadata and knows the
correct chunk size before writing.

Changes:
- Added FILETREE_BADGEN error code (-8)
- Modified file_tree_write() to reject expect_gen=0
- Added error message for FILETREE_BADGEN
This commit is contained in:
Claude
2025-11-24 12:46:27 +00:00
parent acb1336d47
commit 1281bf0822
2 changed files with 6 additions and 0 deletions
+5
View File
@@ -366,6 +366,10 @@ int file_tree_write(FileTree *ft, string path,
SHA256 *removed_hashes,
int *num_removed)
{
// Per protocol spec, WRITE operations cannot use expect_gen=0
if (expect_gen == NO_GENERATION)
return FILETREE_BADGEN;
int num_comps;
string comps[MAX_COMPS];
@@ -534,6 +538,7 @@ string file_tree_strerror(int code)
case FILETREE_EXISTS : return S("File or directory already exists");
case FILETREE_BADPATH: return S("Invalid path");
case FILETREE_BADOP : return S("Invalid operation");
case FILETREE_BADGEN : return S("Generation counter cannot be zero for write operations");
default:break;
}
return S("Unknown error");
+1
View File
@@ -13,6 +13,7 @@ enum {
FILETREE_EXISTS = -5,
FILETREE_BADPATH = -6,
FILETREE_BADOP = -7,
FILETREE_BADGEN = -8,
};
typedef struct Entity Entity;