jaros1 / Money-Network

Demo with complementary and alternative money. Implemented in ZeroNet and AngularJS. Focus on privacy, encryption, max data in client and min data on ZeroNet. Work in progress.
GNU General Public License v2.0
4 stars 4 forks source link

MoneyNetworkAPI. add z_file_delete wrapper #290

Closed jaros1 closed 6 years ago

jaros1 commented 6 years ago

See https://github.com/HelloZeroNet/ZeroNet/issues/1140

                                            // issue #1140. https://github.com/HelloZeroNet/ZeroNet/issues/1140
                                            // false Delete error: [Errno 2] No such file or directory error returned from fileDelete
                                            // step 1: check file before delete operation
                                            debug_seq1 = MoneyNetworkAPILib.debug_z_api_operation_start(pgm, inner_path, 'fileGet');
                                            MoneyNetworkAPILib.z_file_get(pgm, {inner_path: inner_path, required: false, timeout: 1}, function (res1) {
                                                var pgm = service + '.create_sessions.step_3_find_old_outgoing_files.delete_file z_file_get callback 1: ';
                                                var debug_seq2;
                                                MoneyNetworkAPILib.debug_z_api_operation_end(debug_seq1, res1 ? 'OK' : 'Not found');
                                                if (!res1) {
                                                    console.log(pgm + 'warning. optional file ' + inner_path + ' was not found');
                                                    // continue with next file
                                                    delete_failed.push(filename) ;
                                                    delete_file(transaction_timestamp);
                                                    return;
                                                }
                                                // step 2: fileDelete
                                                debug_seq2 = MoneyNetworkAPILib.debug_z_api_operation_start(pgm, inner_path, 'fileDelete');
                                                ZeroFrame.cmd("fileDelete", inner_path, function (res2) {
                                                    var pgm = service + '.create_sessions.step_3_find_old_outgoing_files.delete_file fileDelete callback 2: ';
                                                    var debug_seq3;
                                                    if ((res2 == 'ok') || (!res2.error.match(/No such file or directory/))) {
                                                        MoneyNetworkAPILib.debug_z_api_operation_end(debug_seq2, res2 == 'ok' ? 'OK' : 'Failed. error = ' + JSON.stringify(res2));
                                                        // continue with next file
                                                        delete_file(transaction_timestamp);
                                                        return;
                                                    }
                                                    // step 3: check file after fileDelete
                                                    // fileDelete returned No such file or directory. Recheck that file has been deleted
                                                    console.log(pgm + 'issue 1140. https://github.com/HelloZeroNet/ZeroNet/issues/1140. step 2 FileDelete returned No such file or directory');
                                                    debug_seq3 = MoneyNetworkAPILib.debug_z_api_operation_start(pgm, inner_path, 'fileGet');
                                                    MoneyNetworkAPILib.z_file_get(pgm, {inner_path: inner_path, required: false, timeout: 1}, function (res3) {
                                                        var pgm = service + '.create_sessions.step_3_find_old_outgoing_files.delete_file fileGet callback 3: ';
                                                        MoneyNetworkAPILib.debug_z_api_operation_end(debug_seq3, res3 ? 'OK' : 'Not found');
                                                        if (!res3) {
                                                            // everything is fine. request file was deleted correct in step 2
                                                            MoneyNetworkAPILib.debug_z_api_operation_end(debug_seq2, 'OK');
                                                        }
                                                        else {
                                                            console.log(pgm + 'issue 1140. something is very wrong. first fileGet returned OK, fileDelete returned No such file or directory and last fileGet returned OK');
                                                            MoneyNetworkAPILib.debug_z_api_operation_end(debug_seq2, res2 == 'ok' ? 'OK' : 'Failed. error = ' + JSON.stringify(res2));
                                                            delete_failed.push(filename);                                                            }
                                                        // continue with next file
                                                        delete_file(transaction_timestamp);
                                                    });
                                                }); // fileDelete callback

                                            }); // fileGet callback