Skip to content

Commit

Permalink
fix: magnet link task moveTaskFilesToTrash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Feb 24, 2019
1 parent 084f834 commit e488de5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/renderer/components/Native/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import is from 'electron-is'
import { existsSync } from 'fs'
import { Message } from 'element-ui'
import {
isMagnetTask,
getTaskFullPath,
bytesToSize
} from '@shared/utils'
Expand Down Expand Up @@ -41,6 +42,15 @@ export function openItem (fullPath, { errorMsg }) {
}

export function moveTaskFilesToTrash (task, messages = {}) {
/**
* 磁力链接任务,有 bittorrent,但没有 bittorrent.info ,
* 在没下完变成BT任务之前 path 不是一个完整路径,
* 未避免误删所在目录,所以删除时直接返回 true
*/
if (isMagnetTask(task)) {
return true
}

const { pathErrorMsg, delFailMsg, delConfigFailMsg } = messages
const { dir } = task
const path = getTaskFullPath(task)
Expand Down
24 changes: 17 additions & 7 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
camelCase,
kebabCase
} from 'lodash'
import { resolve } from 'path'
import { userKeys, systemKeys } from './configKeys'

export function bytesToSize (bytes) {
Expand Down Expand Up @@ -140,32 +141,41 @@ export function getFileName (file) {

export function getTaskFullPath (task) {
const { dir, files, bittorrent } = task
let result = dir
let result = resolve(dir)

if (bittorrent && bittorrent.info && bittorrent.info.name) {
result = `${result}/${bittorrent.info.name}`
// Magnet link task
if (isMagnetTask(task)) {
return result
}

if (bittorrent.info && bittorrent.info.name) {
result = resolve(result, bittorrent.info.name)
return result
}

const [file] = files
const { path } = file
const path = resolve(file.path)
let fileName = ''

if (path) {
// Magnet task file's path did not start with dir
result = path.startsWith(dir) ? path : result
result = path
} else {
if (files && files.length === 1) {
fileName = getFileName(file)
if (fileName) {
result = `${result}/${fileName}`
result = resolve(result, fileName)
}
}
}

return result
}

export function isMagnetTask (task) {
const { bittorrent } = task
return bittorrent && !bittorrent.info
}

export function getTaskUri (task, btTracker = []) {
const { files } = task
let result = ''
Expand Down

0 comments on commit e488de5

Please sign in to comment.