--- parser3/src/classes/file.C 2016/12/28 17:41:15 1.259 +++ parser3/src/classes/file.C 2019/09/11 15:26:08 1.265 @@ -1,7 +1,7 @@ /** @file Parser: @b file parser class. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -25,7 +25,7 @@ #include "pa_vregex.h" #include "pa_version.h" -volatile const char * IDENT_FILE_C="$Id: file.C,v 1.259 2016/12/28 17:41:15 moko Exp $"; +volatile const char * IDENT_FILE_C="$Id: file.C,v 1.265 2019/09/11 15:26:08 moko Exp $"; // defines @@ -192,7 +192,7 @@ static void _move(Request& r, MethodPara keep_empty_dirs); } -static void copy_process_source(struct stat& , int from_file, const String&, void *context) { +static void copy_process_source(struct stat&, int from_file, const String&, void *context) { int& to_file=*static_cast(context); int nCount=0; @@ -217,6 +217,18 @@ static void _copy(Request& r, MethodPara Value& vfrom_file_name=params.as_no_junction(0, "from file name must not be code"); Value& vto_file_name=params.as_no_junction(1, "to file name must not be code"); + bool append=false; + if(params.count()>2) + if(HashStringValue* options=params.as_hash(2)){ + int valid_options=0; + if(Value* vappend=options->get("append")){ + append=r.process(*vappend).as_bool(); + valid_options++; + } + if(valid_options != options->count()) + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); + } + String from_spec = r.absolute(vfrom_file_name.as_string()); const String& to_spec = r.absolute(vto_file_name.as_string()); @@ -224,7 +236,9 @@ static void _copy(Request& r, MethodPara to_spec, "copy", copy_open_target, - &from_spec); + &from_spec, + false /*as text*/, + append); } static void _load_pass_param( @@ -730,10 +744,10 @@ static void _list(Request& r, MethodPara int ovector[ovector_size]; LOAD_DIR(absolute_path_cstr, - const char* file_name_cstr=ffblk.ff_name; + const char* file_name_cstr=ffblk.name(); size_t file_name_size=strlen(file_name_cstr); - if(!vregex || vregex->exec(ffblk.ff_name, file_name_size, ovector, ovector_size)>=0) { + if(!vregex || vregex->exec(file_name_cstr, file_name_size, ovector, ovector_size)>=0) { Table::element_type row(new ArrayString); *row+=new String(pa_strdup(file_name_cstr, file_name_size), String::L_TAINTED); *row+=new String(String::Body::Format(ffblk.is_dir(stat) ? 1 : 0), String::L_CLEAN); @@ -939,7 +953,6 @@ static void _sql_string(Request& r, Meth #ifndef DOXYGEN class File_sql_event_handlers: public SQL_Driver_query_event_handlers { - const String& statement_string; const char* statement_cstr; int got_columns; int got_cells; public: @@ -947,9 +960,7 @@ public: const String* user_file_name; const String* user_content_type; public: - File_sql_event_handlers( - const String& astatement_string, const char* astatement_cstr): - statement_string(astatement_string), statement_cstr(astatement_cstr), + File_sql_event_handlers(): got_columns(0), got_cells(0), user_file_name(0), @@ -957,7 +968,7 @@ public: bool add_column(SQL_Error& error, const char* /*str*/, size_t /*length*/) { if(got_columns++==3) { - error=SQL_Error(PARSER_RUNTIME, "result must contain not more then 3 columns"); + error=SQL_Error("result must contain not more then 3 columns"); return true; } return false; @@ -979,12 +990,12 @@ public: user_content_type=new String(str, String::L_TAINTED); break; default: - error=SQL_Error(PARSER_RUNTIME, "result must not contain more then one row, three columns"); + error=SQL_Error("result must not contain more then one row, three columns"); return true; } return false; } catch(...) { - error=SQL_Error("exception occured in File_sql_event_handlers::add_row_cell"); + error=SQL_Error("exception occurred in File_sql_event_handlers::add_row_cell"); return true; } } @@ -996,7 +1007,7 @@ static void _sql(Request& r, MethodParam const String& statement_string=r.process_to_string(statement); const char* statement_cstr=statement_string.untaint_cstr(String::L_SQL, r.connection()); - File_sql_event_handlers handlers(statement_string, statement_cstr); + File_sql_event_handlers handlers; ulong limit=SQL_NO_LIMIT; ulong offset=0; @@ -1025,12 +1036,7 @@ static void _sql(Request& r, MethodParam } - r.connection()->query( - statement_cstr, - 0, 0, - offset, limit, - handlers, - statement_string); + r.connection()->query(statement_cstr, 0, 0, offset, limit, handlers, statement_string); if(!handlers.value.str) throw Exception(PARSER_RUNTIME, 0, "produced no result"); @@ -1266,5 +1272,6 @@ MFile::MFile(): Methoded("file") { add_native_method("md5", Method::CT_ANY, _md5, 0, 1); // ^file:copy[from-file-name;to-file-name] - add_native_method("copy", Method::CT_STATIC, _copy, 2, 2); + // ^file:copy[from-file-name;to-file-name;$.append(false)] + add_native_method("copy", Method::CT_STATIC, _copy, 2, 3); }