Skip to content

Commit

Permalink
Fix multi-file transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed May 31, 2024
1 parent 722fd82 commit ae08d35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/service/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,13 @@ export const Transfer = GObject.registerClass({
super._init(params);

this._cancellable = new Gio.Cancellable();
// Separate because we want to delete temporaries even if cancelled.
this._delete_cancellable = new Gio.Cancellable();
this._items = [];
this._temporaries = [];
this._count = 0;
this._totalSize = 0;
this._multiFile = false;
}

get channel() {
Expand Down Expand Up @@ -659,6 +662,7 @@ export const Transfer = GObject.registerClass({
setCountAndSize(numberOfFiles, totalPayloadSize) {
this._count = numberOfFiles;
this._totalSize = totalPayloadSize;
this._multiFile = true;

const item = {
packet: new Packet({
Expand Down Expand Up @@ -719,8 +723,10 @@ export const Transfer = GObject.registerClass({
await this.channel.download(item.packet, item.target,
this._cancellable);
} else {
item.packet.body.numberOfFiles = this._count;
item.packet.body.totalPayloadSize = this._totalSize;
if (this._multiFile) {
item.packet.body.numberOfFiles = this._count;
item.packet.body.totalPayloadSize = this._totalSize;
}
await this.channel.upload(item.packet, item.source,
item.size, this._cancellable);
}
Expand All @@ -730,6 +736,7 @@ export const Transfer = GObject.registerClass({
error = e;
} finally {
this._completed = true;
// Delete temporaries even on error, to avoid polluting tempdir
this._process_deletes();
this.notify('completed');
}
Expand All @@ -747,7 +754,8 @@ export const Transfer = GObject.registerClass({
let tempfile;
while ((tempfile = this._temporaries.shift())) {
try {
await tempfile.delete_async(this._cancellable);
debug(`deleting ${tempfile.name}`);
await tempfile.delete_async(this._delete_cancellable, null);
} catch (e) {
logError(e, 'GSConnect');
}
Expand Down
18 changes: 10 additions & 8 deletions src/service/plugins/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Metadata = {
incomingCapabilities: ['kdeconnect.share.request'],
outgoingCapabilities: [
'kdeconnect.share.request',
'kdeconnect.share.request.update'
'kdeconnect.share.request.update',
],
actions: {
share: {
Expand Down Expand Up @@ -51,6 +51,8 @@ export const Metadata = {
},
shareFilesWithTemps: {
label: _('Share Files (including temporaries)'),

parameter_type: new GLib.VariantType('(asas)'),
incoming: [],
outgoing: [
'kdeconnect.share.request',
Expand Down Expand Up @@ -399,13 +401,14 @@ const SharePlugin = GObject.registerClass({
const info = await file.query_info_async(
Gio.FILE_ATTRIBUTE_STANDARD_SIZE,
Gio.FileQueryInfoFlags.NONE,
GLib.PRIORITY_DEFAULT
GLib.PRIORITY_DEFAULT,
null
);

const filesize = info.get_size();
payload_size += filesize;

const delete_after = tempList.contains(path);
const delete_after = tempList.includes(path);

packet_list.push([
{
Expand Down Expand Up @@ -643,12 +646,11 @@ const FileChooserDialog = GObject.registerClass({
vfunc_response(response_id) {
if (response_id === Gtk.ResponseType.OK) {
const uris = [];
for (const uri of this.get_uris()) {
uris.push(uri);
}
for (const uri of this.get_uris())
uris.push(uri);
const parameters = new GLib.Variant('(asb)', [
uris,
this.extra_widget.active,
uris,
this.extra_widget.active,
]);
debug(parameters.deepUnpack());
this.device.activate_action('shareFiles', parameters);
Expand Down

0 comments on commit ae08d35

Please sign in to comment.