VictoriaFreSh 2021.8.20 → 2022.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/victoriafresh.rb +29 -18
- 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: 41105b47d70e0d767e72badf4280f170ca7654668f344255b2718ce6a46f827c
|
4
|
+
data.tar.gz: 218bdf0c648500f0c518cc1f4d84515528ebbb7512dd0e876c1957bbe26414d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea4abcee34ca2430ba9756e2ded00872c373c8ba2eff827a4d163d31556a5ec5bb793a2eb51a2bd65a4a8cfc1297174ed631756958b07de4bad8ae166f76d6b
|
7
|
+
data.tar.gz: 5bc98b7f1f12f007c2f38cd90fdee5c7f123576f8bf9780908ea2335a06afc01099745e9b47ac67f72e66eb0ee2fe2a37b1cc72b74ed447943eba661f6b0e003
|
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,20 @@ class VictoriaFresh
|
|
25
26
|
@currentDiskFlushSuffix=0 #当前的磁盘文件后缀
|
26
27
|
@bufferLength=0 #缓冲区总长度
|
27
28
|
@externalDataFile={} #外部数据文件对象
|
29
|
+
@nextFileIdToUse=1 # 下一个要用的文件编号。
|
30
|
+
@md5FileIdMap={} # MD5 与文件编号之间的映射
|
31
|
+
end
|
32
|
+
|
33
|
+
# 计算文件内容的MD5。
|
34
|
+
def calculateMd5(currentFileContent)
|
35
|
+
Digest::MD5.hexdigest currentFileContent #=> "90015098..."
|
36
|
+
end
|
37
|
+
|
38
|
+
# 下一个可用的文件编号
|
39
|
+
def nextFileId
|
40
|
+
result=@nextFileIdToUse # 结果
|
41
|
+
|
42
|
+
@nextFileIdToUse=@nextFileIdToUse+1
|
28
43
|
end
|
29
44
|
|
30
45
|
def checkMemoryUsage(lineNumber)
|
@@ -320,8 +335,6 @@ class VictoriaFresh
|
|
320
335
|
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
321
336
|
|
322
337
|
@diskWriteFileObject.close
|
323
|
-
|
324
|
-
|
325
338
|
else #单个磁盘文件
|
326
339
|
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
327
340
|
|
@@ -377,19 +390,29 @@ class VictoriaFresh
|
|
377
390
|
|
378
391
|
if isFile #是文件,不用再列出其子文件了。
|
379
392
|
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
393
|
+
packagedFile['id']= nextFileId # 设置下一个文件编号
|
380
394
|
|
381
395
|
#读取文件内容:
|
382
396
|
fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
383
397
|
currentFileContent=fileToReadContent.read #全部读取
|
384
|
-
|
385
|
-
|
386
|
-
|
398
|
+
|
399
|
+
currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
|
400
|
+
|
401
|
+
sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
|
402
|
+
|
403
|
+
if sameFileId.nil? # 不存在相同的文件
|
404
|
+
@contentPartArray << currentFileContent
|
405
|
+
@bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
|
406
|
+
@md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
|
407
|
+
else # 存在相同的文件
|
408
|
+
packagedFile['is_duplicate']=true # 是重复文件。
|
409
|
+
packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
|
410
|
+
end # if sameFileId.nil? # 不存在相同的文件
|
387
411
|
|
388
412
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
389
413
|
elsif (isSymLink) #是符号链接
|
390
414
|
linkTarget=directoryPathName.readlink #获取链接目标
|
391
415
|
|
392
|
-
# 待续,设置内容长度。符号链接字符串的长度
|
393
416
|
packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
|
394
417
|
|
395
418
|
#读取文件内容:
|
@@ -397,12 +420,9 @@ class VictoriaFresh
|
|
397
420
|
currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
398
421
|
@contentPartArray << currentFileContent #加入数组
|
399
422
|
@bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
|
400
|
-
# @contentString= @contentString + StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
401
423
|
|
402
424
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
403
|
-
|
404
425
|
else #是目录。
|
405
|
-
# contentString="" #容纳内容的字符串。
|
406
426
|
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
407
427
|
|
408
428
|
packagedFile['file_length']=0 #本目录的内容长度。
|
@@ -410,9 +430,6 @@ class VictoriaFresh
|
|
410
430
|
puts "Listing for #{directoryPathName}" # Debug
|
411
431
|
|
412
432
|
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
433
|
begin
|
417
434
|
realPath=subFile.expand_path #获取绝对路径。
|
418
435
|
|
@@ -420,12 +437,6 @@ class VictoriaFresh
|
|
420
437
|
|
421
438
|
packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
|
422
439
|
|
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
440
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
430
441
|
|
431
442
|
|
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.8
|
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: []
|