@@ -3239,22 +3239,57 @@ count = glob_cp ./**/*.txt ../target
32393239
32403240` ` ` sh
32413241
3242- scope::glob_cp::handle = glob_array ${scope:: glob_cp:: argument:: 1}
3243- scope::glob_cp::output = set 0
3242+ scope::glob_cp::contains_glob = contains ${scope:: glob_cp:: argument:: 1} *
32443243scope::glob_cp::target = set ${scope:: glob_cp:: argument:: 2}
3244+ scope::glob_cp::output = set 0
32453245
3246- for scope::glob_cp::entry in ${scope:: glob_cp:: handle}
3247- scope::glob_cp::is_file = is_file ${scope:: glob_cp:: entry}
3246+ if ${scope:: glob_cp:: contains_glob}
3247+ scope::glob_cp::handle = glob_array ${scope:: glob_cp:: argument:: 1}
3248+ scope::glob_cp::glob_empty = array_is_empty ${scope:: glob_cp:: handle}
32483249
3249- if ${scope:: glob_cp:: is_file}
3250- scope::glob_cp::target_file = join_path ${scope:: glob_cp:: target} ${scope:: glob_cp:: entry}
3251- cp ${scope:: glob_cp:: entry} ${scope:: glob_cp:: target_file}
3250+ if not ${scope:: glob_cp:: glob_empty}
3251+ scope::glob_cp::is_relative = starts_with ${scope:: glob_cp:: argument:: 1} .
3252+ if not ${scope:: glob_cp:: is_relative}
3253+ scope::glob_cp::top_dir_without_glob = set ${scope:: glob_cp:: argument:: 1}
3254+ while contains ${scope:: glob_cp:: top_dir_without_glob} *
3255+ scope::glob_cp::top_dir_without_glob = dirname ${scope:: glob_cp:: top_dir_without_glob}
3256+ end
3257+
3258+ scope::glob_cp::absolute_prefix_length = strlen ${scope:: glob_cp:: top_dir_without_glob}
3259+ end
3260+
3261+ for scope::glob_cp::entry in ${scope:: glob_cp:: handle}
3262+ scope::glob_cp::is_file = is_file ${scope:: glob_cp:: entry}
3263+
3264+ if ${scope:: glob_cp:: is_file}
3265+ if ${scope:: glob_cp:: is_relative}
3266+ scope::glob_cp::target_file = join_path ${scope:: glob_cp:: target} ${scope:: glob_cp:: entry}
3267+ else
3268+ scope::glob_cp::target_file = substring ${scope:: glob_cp:: entry} ${scope:: glob_cp:: absolute_prefix_length}
3269+ scope::glob_cp::target_file = join_path ${scope:: glob_cp:: target} ${scope:: glob_cp:: target_file}
3270+ end
3271+
3272+ scope::glob_cp::done = cp ${scope:: glob_cp:: entry} ${scope:: glob_cp:: target_file}
32523273
3253- scope::glob_cp::output = calc ${scope:: glob_cp:: output} + 1
3274+ if ${scope:: glob_cp:: done}
3275+ scope::glob_cp::output = calc ${scope:: glob_cp:: output} + 1
3276+ end
3277+ end
3278+ end
32543279 end
3255- end
32563280
3257- release ${scope:: glob_cp:: handle}
3281+ release ${scope:: glob_cp:: handle}
3282+ else
3283+ scope::glob_cp::is_file = is_file ${scope:: glob_cp:: argument:: 1}
3284+
3285+ if ${scope:: glob_cp:: is_file}
3286+ scope::glob_cp::filename = basename ${scope:: glob_cp:: argument:: 1}
3287+ scope::glob_cp::done = cp ${scope:: glob_cp:: argument:: 1} ${scope:: glob_cp:: target} /${scope:: glob_cp:: filename}
3288+ if ${scope:: glob_cp:: done}
3289+ scope::glob_cp::output = set 1
3290+ end
3291+ end
3292+ end
32583293
32593294set ${scope:: glob_cp:: output}
32603295
0 commit comments