VictoriaFreSh 2021.7.30 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68a7f71cfa42efd3573dd7298e0d579b45e4d6af7e46d8fbd7b15cae24c8c89b
4
- data.tar.gz: 9128f0401e38595100de90f021d58958f531b37fea424db7df50a8b1bf9eb7f1
3
+ metadata.gz: 41105b47d70e0d767e72badf4280f170ca7654668f344255b2718ce6a46f827c
4
+ data.tar.gz: 218bdf0c648500f0c518cc1f4d84515528ebbb7512dd0e876c1957bbe26414d6
5
5
  SHA512:
6
- metadata.gz: a8914a283371b1c65cfc4a5e50bb63e5a5193fe3e112b5ebbf34b0e76ab2462768cc794a6e25bde45ac612999f8e92ec0c1e7e328d6ed3c1c9531510dcf647bf
7
- data.tar.gz: 2094cec3f9179bf6cfdf621f8550c30d568e01082bbfae680b6ddab7f0a0cdfb55c647af8722c64b602bf73343f869adfece058a263d6afdcbf7ce9bac6734e3
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
 
@@ -375,21 +388,31 @@ class VictoriaFresh
375
388
  rescue Errno::EACCES #权限受限
376
389
  end #begin #读取时间戳
377
390
 
378
- if (isFile) #是文件,不用再列出其子文件了。
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
- @contentPartArray << currentFileContent
385
- @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
386
- # @contentString= @contentString + fileToReadContent.read #全部读取。
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,31 +420,23 @@ 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 #本目录的内容长度。
409
-
429
+
430
+ puts "Listing for #{directoryPathName}" # Debug
431
+
410
432
  directoryPathName.each_child do |subFile| #一个个文件地处理。
411
- # puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
412
- # checkMemoryUsage(221)
433
+ begin
413
434
  realPath=subFile.expand_path #获取绝对路径。
414
435
 
415
436
  packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
416
437
 
417
438
  packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
418
439
 
419
- # puts("sub file content: #{subFileContent}, nil?: #{subFileContent.nil?}" ) #Debug
420
-
421
- # puts(" content: #{contentString}, nil?: #{contentString.nil? }") #Debug
422
-
423
- # contentString = contentString + subFileContent #串接文件内容。
424
-
425
440
  assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
426
441
 
427
442
 
@@ -430,6 +445,9 @@ class VictoriaFresh
430
445
  # puts("237, content string length: #{contentString.length}") #Debug
431
446
 
432
447
  packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
448
+ rescue Errno::EMFILE # File not exist
449
+ puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
450
+ end
433
451
  end #directoryPathName.each_child do |subFile| #一个个文件地处理。
434
452
  end #if (isFile) #是文件,不用再列出其子文件了。
435
453
 
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: VictoriaFreSh
3
3
  version: !ruby/object:Gem::Version
4
- version: 2021.7.30
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: 2021-07-30 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: cbor
14
+ name: hx_cbor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.5.9
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 0.5.9.6
19
+ version: 2021.8.20
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 0.5.9
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 0.5.9.6
26
+ version: 2021.8.20
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: get_process_mem
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,13 @@ executables: []
50
44
  extensions: []
51
45
  extra_rdoc_files: []
52
46
  files:
53
- - lib/VictoriaFreSh/filemessage_pb.rb
54
47
  - lib/victoriafresh.rb
55
48
  - victoriafresh.example.rb
56
49
  homepage: http://rubygems.org/gems/VictoriaFreSh
57
50
  licenses:
58
51
  - MIT
59
52
  metadata: {}
60
- post_install_message:
53
+ post_install_message:
61
54
  rdoc_options: []
62
55
  require_paths:
63
56
  - lib
@@ -72,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
65
  - !ruby/object:Gem::Version
73
66
  version: '0'
74
67
  requirements: []
75
- rubygems_version: 3.0.3
76
- signing_key:
68
+ rubygems_version: 3.1.6
69
+ signing_key:
77
70
  specification_version: 4
78
71
  summary: VictoriaFreSh
79
72
  test_files: []
@@ -1,24 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: filemessage.proto
3
-
4
- require 'google/protobuf'
5
-
6
- require 'google/protobuf/timestamp_pb'
7
- Google::Protobuf::DescriptorPool.generated_pool.build do
8
- add_message "com.stupidbeauty.victoriafresh.FileMessage" do
9
- optional :name, :string, 1
10
- repeated :sub_files, :message, 2, "com.stupidbeauty.victoriafresh.FileMessage"
11
- optional :is_file, :bool, 3
12
- optional :file_start_index, :int32, 5
13
- optional :file_length, :int32, 6
14
- optional :timestamp, :message, 8, "google.protobuf.Timestamp"
15
- end
16
- end
17
-
18
- module Com
19
- module Stupidbeauty
20
- module Victoriafresh
21
- FileMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.victoriafresh.FileMessage").msgclass
22
- end
23
- end
24
- end