From c78d3bb3394ebaf8d0d286f81c064dd5352e4931 Mon Sep 17 00:00:00 2001 From: sbcgua Date: Mon, 12 Dec 2016 14:29:45 +0200 Subject: [PATCH] W3xx remove filesize finetune, fixes #495 --- src/zabapgit_css_common.w3mi.xml | 12 --- src/zabapgit_js_common.w3mi.xml | 12 --- src/zabapgit_object_w3xx.prog.abap | 119 +++++++++++++-------------- src/zabapgit_repo.prog.abap | 5 +- src/zabapgit_repo_impl.prog.abap | 36 +++++++- src/zabapgit_services_repo.prog.abap | 8 +- src/zabapgit_view_repo.prog.abap | 4 +- 7 files changed, 102 insertions(+), 94 deletions(-) diff --git a/src/zabapgit_css_common.w3mi.xml b/src/zabapgit_css_common.w3mi.xml index ddab44689..10d1ffd0d 100644 --- a/src/zabapgit_css_common.w3mi.xml +++ b/src/zabapgit_css_common.w3mi.xml @@ -17,24 +17,12 @@ filename ~wwwtmp.css - - MI - ZABAPGIT_CSS_COMMON - filesize - 12615 - MI ZABAPGIT_CSS_COMMON mimetype text/css - - MI - ZABAPGIT_CSS_COMMON - version - - diff --git a/src/zabapgit_js_common.w3mi.xml b/src/zabapgit_js_common.w3mi.xml index 7860ae90e..51f904696 100644 --- a/src/zabapgit_js_common.w3mi.xml +++ b/src/zabapgit_js_common.w3mi.xml @@ -17,24 +17,12 @@ filename common.js - - MI - ZABAPGIT_JS_COMMON - filesize - 6500 - MI ZABAPGIT_JS_COMMON mimetype text/javascript - - MI - ZABAPGIT_JS_COMMON - version - - diff --git a/src/zabapgit_object_w3xx.prog.abap b/src/zabapgit_object_w3xx.prog.abap index f1c17f50d..c14bdc062 100644 --- a/src/zabapgit_object_w3xx.prog.abap +++ b/src/zabapgit_object_w3xx.prog.abap @@ -12,13 +12,20 @@ CLASS lcl_object_w3super DEFINITION INHERITING FROM lcl_objects_super ABSTRACT. PUBLIC SECTION. INTERFACES lif_object. - TYPES: ty_wwwparams_tt TYPE STANDARD TABLE OF wwwparams WITH DEFAULT KEY. + TYPES ty_wwwparams_tt TYPE STANDARD TABLE OF wwwparams WITH DEFAULT KEY. - METHODS: - constructor - IMPORTING - is_item TYPE ty_item - iv_language TYPE spras. + CONSTANTS: BEGIN OF c_param_names, + version TYPE w3_name VALUE 'version', + fileext TYPE w3_name VALUE 'fileextension', + filesize TYPE w3_name VALUE 'filesize', + filename TYPE w3_name VALUE 'filename', + mimetype TYPE w3_name VALUE 'mimetype', + END OF c_param_names. + + METHODS constructor + IMPORTING + is_item TYPE ty_item + iv_language TYPE spras. PROTECTED SECTION. @@ -33,18 +40,19 @@ CLASS lcl_object_w3super DEFINITION INHERITING FROM lcl_objects_super ABSTRACT. RETURNING VALUE(rv_ext) TYPE string RAISING lcx_exception. - METHODS patch_size - IMPORTING iv_size TYPE i OPTIONAL " Overwrite if given - EXPORTING ev_size TYPE i " Return size as integer + METHODS normalize_params + IMPORTING iv_size TYPE i CHANGING ct_params TYPE ty_wwwparams_tt " Param table to patch RAISING lcx_exception. - METHODS patch_filename + METHODS strip_params CHANGING ct_params TYPE ty_wwwparams_tt RAISING lcx_exception. - METHODS clear_version - CHANGING ct_params TYPE ty_wwwparams_tt + METHODS find_param + IMPORTING it_params TYPE ty_wwwparams_tt + iv_name TYPE w3_name + RETURNING VALUE(rv_value) TYPE string RAISING lcx_exception. ENDCLASS. "lcl_object_W3SUPER DEFINITION @@ -145,15 +153,9 @@ CLASS lcl_object_w3super IMPLEMENTATION. lcx_exception=>raise( 'Cannot read W3xx data' ). ENDIF. - " Condense size string + get size to local integer - patch_size( IMPORTING ev_size = lv_size - CHANGING ct_params = lt_w3params ). - - " Remove file path (for security concerns) - patch_filename( CHANGING ct_params = lt_w3params ). - - " Clear version - clear_version( CHANGING ct_params = lt_w3params ). + lv_size = find_param( it_params = lt_w3params iv_name = c_param_names-filesize ). + " Clean params (remove version, filesize & clear filename from path) + strip_params( CHANGING ct_params = lt_w3params ). CASE ms_key-relid. WHEN 'MI'. @@ -264,11 +266,9 @@ CLASS lcl_object_w3super IMPLEMENTATION. lcx_exception=>raise( 'Wrong W3xx type' ). ENDCASE. - " Update size of file (for the case file was actually changed remotely) - " Will also trigger "stage" at next sync if remote XML - " was not updated with the new file size - patch_size( EXPORTING iv_size = lv_size - CHANGING ct_params = lt_w3params ). + " Update size of file based on actual data file size, prove param object name + normalize_params( EXPORTING iv_size = lv_size + CHANGING ct_params = lt_w3params ). CALL FUNCTION 'WWWPARAMS_UPDATE' TABLES @@ -368,67 +368,60 @@ CLASS lcl_object_w3super IMPLEMENTATION. METHOD get_ext. - FIELD-SYMBOLS LIKE LINE OF it_params. - - READ TABLE it_params ASSIGNING WITH KEY name = 'fileextension'. - - IF sy-subrc > 0. - lcx_exception=>raise( |W3xx: Cannot find file ext for { ms_key-objid }| ). - ENDIF. - - rv_ext = -value. + rv_ext = find_param( it_params = it_params iv_name = c_param_names-fileext ). SHIFT rv_ext LEFT DELETING LEADING '.'. ENDMETHOD. " get_ext. - METHOD patch_size. + METHOD normalize_params. FIELD-SYMBOLS LIKE LINE OF ct_params. - READ TABLE ct_params ASSIGNING WITH KEY name = 'filesize'. - - IF sy-subrc > 0. - lcx_exception=>raise( |W3xx: Cannot find file size for { ms_key-objid }| ). + " Ensure filesize param exists + READ TABLE ct_params ASSIGNING WITH KEY name = c_param_names-filesize. + IF sy-subrc <> 0. + APPEND INITIAL LINE TO ct_params ASSIGNING . + -name = c_param_names-filesize. ENDIF. - IF iv_size IS NOT INITIAL. - -value = iv_size. - ENDIF. - CONDENSE -value. + LOOP AT ct_params ASSIGNING . + -relid = ms_key-relid. " Ensure param key = object key + -objid = ms_key-objid. + IF -name = c_param_names-filesize. " Patch filesize = real file size + -value = iv_size. + CONDENSE -value. + ENDIF. + ENDLOOP. - ev_size = -value. + ENDMETHOD. " normalize_params. - ENDMETHOD. " patch_size. - - METHOD patch_filename. + METHOD strip_params. FIELD-SYMBOLS LIKE LINE OF ct_params. - READ TABLE ct_params ASSIGNING WITH KEY name = 'filename'. - - IF sy-subrc > 0. - lcx_exception=>raise( |W3xx: Cannot find file name for { ms_key-objid }| ). - ENDIF. - - " Remove path + " Remove path from filename + find_param( it_params = ct_params iv_name = c_param_names-filename ). " Check exists + READ TABLE ct_params ASSIGNING WITH KEY name = c_param_names-filename. -value = lcl_path=>get_filename_from_syspath( |{ -value }| ). - ENDMETHOD. " patch_filename. + " Clear version & filesize + DELETE ct_params WHERE name = c_param_names-version. + DELETE ct_params WHERE name = c_param_names-filesize. - METHOD clear_version. + ENDMETHOD. " strip_params. - FIELD-SYMBOLS LIKE LINE OF ct_params. + METHOD find_param. - READ TABLE ct_params ASSIGNING WITH KEY name = 'version'. + FIELD-SYMBOLS LIKE LINE OF it_params. + READ TABLE it_params ASSIGNING WITH KEY name = iv_name. IF sy-subrc > 0. - lcx_exception=>raise( |W3xx: Cannot find version for { ms_key-objid }| ). + lcx_exception=>raise( |W3xx: Cannot find { iv_name } for { ms_key-objid }| ). ENDIF. - " Clear version - CLEAR -value. + rv_value = -value. - ENDMETHOD. " clear_version. + ENDMETHOD. " find_param. METHOD lif_object~compare_to_remote_version. CREATE OBJECT ro_comparison_result TYPE lcl_null_comparison_result. diff --git a/src/zabapgit_repo.prog.abap b/src/zabapgit_repo.prog.abap index bc9646648..6d6eb40b5 100644 --- a/src/zabapgit_repo.prog.abap +++ b/src/zabapgit_repo.prog.abap @@ -46,6 +46,8 @@ CLASS lcl_repo DEFINITION ABSTRACT FRIENDS lcl_repo_srv. update_local_checksums IMPORTING it_files TYPE ty_file_signatures_tt RAISING lcx_exception, + rebuild_local_checksums + RAISING lcx_exception, is_offline RETURNING VALUE(rv_offline) TYPE abap_bool RAISING lcx_exception. @@ -118,8 +120,7 @@ CLASS lcl_repo_online DEFINITION INHERITING FROM lcl_repo FINAL. RETURNING VALUE(rt_results) TYPE ty_results_tt RAISING lcx_exception, reset_status, - rebuild_local_checksums - RAISING lcx_exception, + rebuild_local_checksums REDEFINITION, push IMPORTING is_comment TYPE ty_comment io_stage TYPE REF TO lcl_stage diff --git a/src/zabapgit_repo_impl.prog.abap b/src/zabapgit_repo_impl.prog.abap index ed9bc0599..4953a8fa1 100644 --- a/src/zabapgit_repo_impl.prog.abap +++ b/src/zabapgit_repo_impl.prog.abap @@ -243,7 +243,7 @@ CLASS lcl_repo_online IMPLEMENTATION. ENDMETHOD. - METHOD rebuild_local_checksums. + METHOD rebuild_local_checksums. "REMOTE DATA: lt_remote TYPE ty_files_tt, lt_local TYPE ty_files_item_tt, @@ -639,6 +639,40 @@ CLASS lcl_repo IMPLEMENTATION. rv_yes = ms_data-write_protect. ENDMETHOD. "is_write_protected + METHOD rebuild_local_checksums. "LOCAL (BASE) + + DATA: lt_local TYPE ty_files_item_tt, + ls_last_item TYPE ty_item, + lt_checksums TYPE lcl_persistence_repo=>ty_local_checksum_tt. + + FIELD-SYMBOLS: LIKE LINE OF lt_checksums, + LIKE LINE OF -files, + LIKE LINE OF lt_local. + + lt_local = get_files_local( ). + + DELETE lt_local " Remove non-code related files except .abapgit + WHERE item IS INITIAL + AND NOT ( file-path = gc_root_dir AND file-filename = gc_dot_abapgit ). + + SORT lt_local BY item. + + LOOP AT lt_local ASSIGNING . + IF ls_last_item <> -item OR sy-tabix = 1. " First or New item reached ? + APPEND INITIAL LINE TO lt_checksums ASSIGNING . + -item = -item. + ls_last_item = -item. + ENDIF. + + APPEND INITIAL LINE TO -files ASSIGNING . + MOVE-CORRESPONDING -file TO . + + ENDLOOP. + + set( it_checksums = lt_checksums ). + + ENDMETHOD. " rebuild_local_checksums. + ENDCLASS. "lcl_repo IMPLEMENTATION *----------------------------------------------------------------------* diff --git a/src/zabapgit_services_repo.prog.abap b/src/zabapgit_services_repo.prog.abap index 0a4858a85..2c9863854 100644 --- a/src/zabapgit_services_repo.prog.abap +++ b/src/zabapgit_services_repo.prog.abap @@ -265,16 +265,20 @@ CLASS lcl_services_repo IMPLEMENTATION. DATA: lv_answer TYPE c, lv_question TYPE string, - lo_repo TYPE REF TO lcl_repo_online. + lo_repo TYPE REF TO lcl_repo. lo_repo ?= lcl_app=>repo_srv( )->get( iv_key ). - lv_question = 'This will rebuild and overwrite local repo checksums.' + lv_question = 'This will rebuild and overwrite local repo checksums.'. + + IF lo_repo->is_offline( ) = abap_false. + lv_question = lv_question && ' The logic: if local and remote file differs then:' && ' if remote branch is ahead then assume changes are remote,' && ' else (branches are equal) assume changes are local.' && ' This will lead to incorrect state for files changed on both sides.' && ' Please make sure you don''t have ones like that.'. + ENDIF. lv_answer = lcl_popups=>popup_to_confirm( titlebar = 'Warning' diff --git a/src/zabapgit_view_repo.prog.abap b/src/zabapgit_view_repo.prog.abap index 70d53ac4d..e71d0064a 100644 --- a/src/zabapgit_view_repo.prog.abap +++ b/src/zabapgit_view_repo.prog.abap @@ -260,12 +260,12 @@ CLASS lcl_gui_view_repo_content IMPLEMENTATION. iv_act = |{ gc_action-repo_remote_change }?{ lv_key }| ). lo_tb_advanced->add( iv_txt = 'Make off-line' iv_act = |{ gc_action-repo_remote_detach }?{ lv_key }| ). - lo_tb_advanced->add( iv_txt = 'Update local checksums' - iv_act = |{ gc_action-repo_refresh_checksums }?{ lv_key }| ). ELSE. lo_tb_advanced->add( iv_txt = 'Make on-line' iv_act = |{ gc_action-repo_remote_attach }?{ lv_key }| ). ENDIF. + lo_tb_advanced->add( iv_txt = 'Update local checksums' + iv_act = |{ gc_action-repo_refresh_checksums }?{ lv_key }| ). lo_tb_advanced->add( iv_txt = 'Remove' iv_act = |{ gc_action-repo_remove }?{ lv_key }| ). lo_tb_advanced->add( iv_txt = 'Uninstall'