Commit 70898b5b authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

add() method will now parse added, last_downloaded, and times_downloaded

These 3 'stats' properties were read-only (never used when adding a file). To support moving files between FileBases while retaining these stats, support the parse/use of these file-meta-object property values.

Should fix issue #333 reported by Nightfox.
parent 5f2881f2
Pipeline #2658 passed with stage
in 9 minutes and 27 seconds
...@@ -572,7 +572,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc ...@@ -572,7 +572,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
uint32_t cost = 0; uint32_t cost = 0;
if(!JS_ValueToECMAUint32(cx, val, &cost)) { if(!JS_ValueToECMAUint32(cx, val, &cost)) {
free(cp); free(cp);
JS_ReportError(cx, "Error converting adding '%s' property to Uint32", prop_name); JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
return SMB_FAILURE; return SMB_FAILURE;
} }
if((file->cost != 0 || cost != 0) && (result = smb_new_hfield(file, SMB_COST, sizeof(cost), &cost)) != SMB_SUCCESS) { if((file->cost != 0 || cost != 0) && (result = smb_new_hfield(file, SMB_COST, sizeof(cost), &cost)) != SMB_SUCCESS) {
...@@ -581,6 +581,36 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc ...@@ -581,6 +581,36 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
return result; return result;
} }
} }
prop_name = "added";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
uint32_t t = 0;
if(!JS_ValueToECMAUint32(cx, val, &t)) {
free(cp);
JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
return SMB_FAILURE;
}
file->hdr.when_imported.time = t;
}
prop_name = "last_downloaded";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
uint32_t t = 0;
if(!JS_ValueToECMAUint32(cx, val, &t)) {
free(cp);
JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
return SMB_FAILURE;
}
file->hdr.last_downloaded = t;
}
prop_name = "times_downloaded";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
uint32_t t = 0;
if(!JS_ValueToECMAUint32(cx, val, &t)) {
free(cp);
JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
return SMB_FAILURE;
}
file->hdr.times_downloaded = t;
}
if(JS_GetProperty(cx, obj, "anon", &val) && val == JSVAL_TRUE) if(JS_GetProperty(cx, obj, "anon", &val) && val == JSVAL_TRUE)
file->hdr.attr |= FILE_ANONYMOUS; file->hdr.attr |= FILE_ANONYMOUS;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment