|
|
| version 1.2, 2001/03/19 20:46:35 | version 1.8, 2001/03/28 09:01:20 |
|---|---|
| Line 12 | Line 12 |
| // global var | // global var |
| VStateless_class *file_base_class; | VStateless_class *file_class; |
| // methods | // methods |
| /// @test mkdirs | |
| static void _save(Request& r, const String& method_name, Array *params) { | static void _save(Request& r, const String& method_name, Array *params) { |
| //\Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value *vfile_name=static_cast<Value *>(params->get(0)); | Value& vfile_name=*static_cast<Value *>(params->get(0)); |
| // forcing | // forcing |
| // ^save{this body type} | // ^save[this body type] |
| r.fail_if_junction_(false, *vfile_name, method_name, "file name must be junction"); | r.fail_if_junction_(true, vfile_name, |
| method_name, "file name must not be junction"); | |
| // forcing untaint language | |
| String lfile_name(pool); | |
| lfile_name.append(vfile_name.as_string(), | |
| String::UL_FILE_NAME, true); | |
| { | // save |
| Temp_lang temp_lang(r, String::Untaint_lang::FILE); | static_cast<VFile *>(r.self)->save(r.absolute(lfile_name)); |
| static_cast<VFile *>(r.self)->save( | } |
| r.absolute(r.process(*vfile_name).as_string().cstr())); | |
| static void _delete(Request& r, const String& method_name, Array *params) { | |
| Pool& pool=r.pool(); | |
| Value& vfile_name=*static_cast<Value *>(params->get(0)); | |
| // forcing | |
| // ^delete[this body type] | |
| r.fail_if_junction_(true, vfile_name, | |
| method_name, "file name must not be junction"); | |
| // forcing untaint language | |
| String lfile_name(pool); | |
| lfile_name.append(vfile_name.as_string(), | |
| String::UL_FILE_NAME, true); | |
| // unlink | |
| file_delete(pool, r.absolute(lfile_name)); | |
| } | |
| static void _find(Request& r, const String& method_name, Array *params) { | |
| Pool& pool=r.pool(); | |
| Value& vfile_name=*static_cast<Value *>(params->get(0)); | |
| // forcing | |
| // ^delete[this body type] | |
| r.fail_if_junction_(true, vfile_name, | |
| method_name, "file name must not be junction"); | |
| // forcing untaint language | |
| String lfile_name(pool); | |
| lfile_name.append(vfile_name.as_string(), | |
| String::UL_FILE_NAME, true); | |
| // passed file name simply exists in current dir | |
| if(file_readable(r.absolute(lfile_name))) { | |
| r.write_no_lang(*new(pool) VString(lfile_name)); | |
| return; | |
| } | |
| // scan .. dirs for result | |
| for(int i=0; i<10; i++) { | |
| String test_name(pool); | |
| for(int j=0; j<i; j++) | |
| test_name.APPEND_CONST("../"); | |
| test_name.append(lfile_name, String::UL_NO); | |
| if(file_readable(r.absolute(test_name))) { | |
| r.write_no_lang(*new(pool) VString(*new(pool) String(test_name))); | |
| return; | |
| } | |
| } | |
| // not found | |
| if(params->size()==2) { | |
| // forcing ..{this body type} | |
| Value& not_found_code=*static_cast<Value *>(params->get(1)); | |
| r.fail_if_junction_(false, not_found_code, | |
| method_name, "not-found param must be junction"); | |
| r.write_pass_lang(r.process(not_found_code)); | |
| } | } |
| } | } |
| // initialize | // initialize |
| void initialize_file_base_class(Pool& pool, VStateless_class& vclass) { | void initialize_file_class(Pool& pool, VStateless_class& vclass) { |
| // ^save[file-name] | // ^save[file-name] |
| vclass.add_native_method("save", _save, 1, 1); | vclass.add_native_method("save", _save, 1, 1); |
| // ^delete[file-name] | |
| vclass.add_native_method("delete", _delete, 1, 1); | |
| // ^find[file-name] | |
| // ^find[file-name]{when-not-found} | |
| vclass.add_native_method("find", _find, 1, 2); | |
| } | } |