VictoriaFreSh 2021.8.20 → 2022.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/victoriafresh.rb +68 -34
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e816682e96950693c25509f5bacef3c369750c4744509b6b4249d07dc3ffb44a
|
4
|
+
data.tar.gz: c6916510d824a4524375dcd88f92aaa24c259a0d8723ea9631352f8f108ef71a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e98134456774cefe3c9f2a22837d3c810365524807218703646643d8c877d2d5d0d5a46f1660a1ef0117746f93dd9f96e879d135dd3aeef9e47072203c3f5967
|
7
|
+
data.tar.gz: 8fd84643f71e5c5a1b016ce444131c324be949d1824d4cf14090b51364fc14d8c3fa8555ffbec96c8983f5565b8f81db9669cd64e0eb1a539eaa82ec8a73f276
|
data/lib/victoriafresh.rb
CHANGED
@@ -4,6 +4,7 @@ require 'pathname'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'cbor'
|
6
6
|
require 'get_process_mem'
|
7
|
+
require 'digest'
|
7
8
|
|
8
9
|
# require File.dirname(__FILE__)+'/VictoriaFreSh/filemessage_pb.rb'
|
9
10
|
|
@@ -25,6 +26,21 @@ class VictoriaFresh
|
|
25
26
|
@currentDiskFlushSuffix=0 #当前的磁盘文件后缀
|
26
27
|
@bufferLength=0 #缓冲区总长度
|
27
28
|
@externalDataFile={} #外部数据文件对象
|
29
|
+
@nextFileIdToUse=1 # 下一个要用的文件编号。
|
30
|
+
@md5FileIdMap={} # MD5 与文件编号之间的映射
|
31
|
+
@fileIdPathMap={} # 文件编号与它的实际路径之间的映射
|
32
|
+
end
|
33
|
+
|
34
|
+
# 计算文件内容的MD5。
|
35
|
+
def calculateMd5(currentFileContent)
|
36
|
+
Digest::MD5.hexdigest currentFileContent #=> "90015098..."
|
37
|
+
end
|
38
|
+
|
39
|
+
# 下一个可用的文件编号
|
40
|
+
def nextFileId
|
41
|
+
result=@nextFileIdToUse # 结果
|
42
|
+
|
43
|
+
@nextFileIdToUse=@nextFileIdToUse+1
|
28
44
|
end
|
29
45
|
|
30
46
|
def checkMemoryUsage(lineNumber)
|
@@ -57,15 +73,31 @@ class VictoriaFresh
|
|
57
73
|
def writeFileExternalDataFile(pathPrefix, packagedFile) #写入文件
|
58
74
|
timeObject=getTimeObject(packagedFile) #构造时间戳对象
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
is_duplicate=packagedFile['is_duplicate'] # 是否是重复文件。
|
77
|
+
fileId=packagedFile['id'] # 获取文件编号。
|
78
|
+
|
79
|
+
if is_duplicate # 是重复文件。
|
80
|
+
sameFileId=packagedFile['same_file_id'] # 找到相同文件的编号。
|
81
|
+
|
82
|
+
sameFilePath=@fileIdPathMap[sameFileId] # 获取原始相同文件的路径。
|
83
|
+
|
84
|
+
victoriaFreshData=File.read(sameFilePath) # 读取原始相同文件的内容。
|
85
|
+
else # 不是重复文件。
|
86
|
+
@externalDataFile.seek(packagedFile['file_start_index']) #定位到起始位置
|
87
|
+
|
88
|
+
victoriaFreshData=@externalDataFile.read(packagedFile['file_length']) #读取内容
|
89
|
+
end # if is_duplicate # 是重复文件。
|
90
|
+
|
91
|
+
if (packagedFile['name']=='hgrc')
|
92
|
+
puts packagedFile # Debug
|
93
|
+
puts victoriaFreshData # Debug
|
94
|
+
end
|
63
95
|
|
64
|
-
|
65
|
-
# victoriaFreshData=contentString[ packagedFile['file_start_index'], packagedFile['file_length'] ] #获取内容
|
96
|
+
|
66
97
|
|
67
|
-
# pathToMake=pathPrefix + '/' + packagedFile.name #构造文件名
|
68
98
|
pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
|
99
|
+
|
100
|
+
@fileIdPathMap[fileId]=pathToMake # 记录文件编号与路径之间的映射。
|
69
101
|
|
70
102
|
begin
|
71
103
|
victoriaFreshDataFile=File.new(pathToMake , "wb", packagedFile['permission']) #数据文件。
|
@@ -80,8 +112,6 @@ class VictoriaFresh
|
|
80
112
|
elsif #带权限字段
|
81
113
|
File.chmod(permissionNumber, pathToMake) #设置权限
|
82
114
|
end #if (permissionNumber.nil?) #不带权限字段
|
83
|
-
|
84
|
-
|
85
115
|
rescue Errno::ENOENT # File not exist
|
86
116
|
puts "Rescued by Errno::ENOENT statement. #{pathToMake}" #报告错误
|
87
117
|
rescue Errno::EACCES # File permission error
|
@@ -320,8 +350,6 @@ class VictoriaFresh
|
|
320
350
|
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
321
351
|
|
322
352
|
@diskWriteFileObject.close
|
323
|
-
|
324
|
-
|
325
353
|
else #单个磁盘文件
|
326
354
|
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
327
355
|
|
@@ -344,8 +372,6 @@ class VictoriaFresh
|
|
344
372
|
|
345
373
|
packagedFile={} #创建文件消息对象。
|
346
374
|
|
347
|
-
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
348
|
-
|
349
375
|
directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
|
350
376
|
|
351
377
|
baseName=directoryPathName.basename.to_s #基本文件名。
|
@@ -360,8 +386,6 @@ class VictoriaFresh
|
|
360
386
|
|
361
387
|
packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
|
362
388
|
|
363
|
-
puts directoryPath #Dbug.
|
364
|
-
|
365
389
|
#记录时间戳:
|
366
390
|
begin #读取时间戳
|
367
391
|
mtimeStamp=File.mtime(directoryPath) #获取时间戳
|
@@ -376,20 +400,44 @@ class VictoriaFresh
|
|
376
400
|
end #begin #读取时间戳
|
377
401
|
|
378
402
|
if isFile #是文件,不用再列出其子文件了。
|
379
|
-
packagedFile['file_length']=
|
403
|
+
packagedFile['file_length']=0 #记录文件的内容长度。
|
404
|
+
packagedFile['id']= nextFileId # 设置下一个文件编号
|
380
405
|
|
381
406
|
#读取文件内容:
|
382
407
|
fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
383
408
|
currentFileContent=fileToReadContent.read #全部读取
|
384
|
-
|
385
|
-
|
386
|
-
|
409
|
+
|
410
|
+
currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
|
411
|
+
|
412
|
+
sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
|
413
|
+
|
414
|
+
if sameFileId.nil? # 不存在相同的文件
|
415
|
+
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
416
|
+
|
417
|
+
@contentPartArray << currentFileContent
|
418
|
+
@bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
|
419
|
+
@md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
|
420
|
+
else # 存在相同的文件
|
421
|
+
packagedFile['is_duplicate']=true # 是重复文件。
|
422
|
+
packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
|
423
|
+
end # if sameFileId.nil? # 不存在相同的文件
|
424
|
+
|
425
|
+
if (packagedFile['name']=='hgrc')
|
426
|
+
puts packagedFile # Debug
|
427
|
+
puts currentFileContent
|
428
|
+
puts @contentPartArray.last
|
429
|
+
puts @contentPartArray.join.length
|
430
|
+
end # if (packagedFile['name']=='hgrc')
|
431
|
+
|
432
|
+
if ((@contentPartArray.join.length-packagedFile['file_length'])!=(packagedFile['file_start_index']))
|
433
|
+
puts packagedFile
|
434
|
+
#raise StandardError
|
435
|
+
end
|
387
436
|
|
388
437
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
389
438
|
elsif (isSymLink) #是符号链接
|
390
439
|
linkTarget=directoryPathName.readlink #获取链接目标
|
391
440
|
|
392
|
-
# 待续,设置内容长度。符号链接字符串的长度
|
393
441
|
packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
|
394
442
|
|
395
443
|
#读取文件内容:
|
@@ -397,22 +445,15 @@ class VictoriaFresh
|
|
397
445
|
currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
398
446
|
@contentPartArray << currentFileContent #加入数组
|
399
447
|
@bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
|
400
|
-
# @contentString= @contentString + StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
401
448
|
|
402
449
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
403
|
-
|
404
450
|
else #是目录。
|
405
|
-
# contentString="" #容纳内容的字符串。
|
406
451
|
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
407
452
|
|
408
453
|
packagedFile['file_length']=0 #本目录的内容长度。
|
409
|
-
|
410
|
-
puts "Listing for #{directoryPathName}" # Debug
|
454
|
+
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
411
455
|
|
412
456
|
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
413
|
-
# puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
|
414
|
-
# checkMemoryUsage(221)
|
415
|
-
|
416
457
|
begin
|
417
458
|
realPath=subFile.expand_path #获取绝对路径。
|
418
459
|
|
@@ -420,15 +461,8 @@ class VictoriaFresh
|
|
420
461
|
|
421
462
|
packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
|
422
463
|
|
423
|
-
# puts("sub file content: #{subFileContent}, nil?: #{subFileContent.nil?}" ) #Debug
|
424
|
-
|
425
|
-
# puts(" content: #{contentString}, nil?: #{contentString.nil? }") #Debug
|
426
|
-
|
427
|
-
# contentString = contentString + subFileContent #串接文件内容。
|
428
|
-
|
429
464
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
430
465
|
|
431
|
-
|
432
466
|
subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
|
433
467
|
|
434
468
|
# puts("237, content string length: #{contentString.length}") #Debug
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: VictoriaFreSh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2022.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hxcan Cai
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hx_cbor
|
@@ -50,7 +50,7 @@ homepage: http://rubygems.org/gems/VictoriaFreSh
|
|
50
50
|
licenses:
|
51
51
|
- MIT
|
52
52
|
metadata: {}
|
53
|
-
post_install_message:
|
53
|
+
post_install_message:
|
54
54
|
rdoc_options: []
|
55
55
|
require_paths:
|
56
56
|
- lib
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubygems_version: 3.1.6
|
69
|
-
signing_key:
|
69
|
+
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: VictoriaFreSh
|
72
72
|
test_files: []
|