util.ts
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { File } from './api/file';
export class Util {
static getNameHash(path:string) {
for(var r=0,i=0;i<path.length;i++) {
r=(r<<5)-r+path.charCodeAt(i),r&=r;
}
return "bsync_" + Math.abs(r);
}
/**
* index >= 0, localFile is in files
* index < 0, localFile is not in files
*/
static getFileIndex(files:Array<File>, localFile:string) : number {
for (let i = 0; i < files.length; i++) {
if (localFile == files[i].target) {
return i;
}
}
return -1;
}
static getFilesForCleanup(files:Array<File>, localFiles:Array<string>) : Array<string> {
let filesForCleanup = [];
for (let localFile of localFiles) {
let index = -1;
index = Util.getFileIndex(files, localFile);
if (index < 0) {
filesForCleanup.push(localFile);
} else {
// splice for performance improvement only
files.splice(index,1);
}
}
return filesForCleanup;
}
}