VictoriaFreSh 2022.1.11 → 2022.2.20

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/victoriafresh.rb +163 -132
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e816682e96950693c25509f5bacef3c369750c4744509b6b4249d07dc3ffb44a
4
- data.tar.gz: c6916510d824a4524375dcd88f92aaa24c259a0d8723ea9631352f8f108ef71a
3
+ metadata.gz: 858f913baefa07976884fe157551cd49be5afed8350a25d7b80b0bf721c3651b
4
+ data.tar.gz: 1b3ec78d1870b2c80e55dff66a75a8fbc3ab090f7b98fbbe015cc7021dd7f494
5
5
  SHA512:
6
- metadata.gz: e98134456774cefe3c9f2a22837d3c810365524807218703646643d8c877d2d5d0d5a46f1660a1ef0117746f93dd9f96e879d135dd3aeef9e47072203c3f5967
7
- data.tar.gz: 8fd84643f71e5c5a1b016ce444131c324be949d1824d4cf14090b51364fc14d8c3fa8555ffbec96c8983f5565b8f81db9669cd64e0eb1a539eaa82ec8a73f276
6
+ metadata.gz: 4a31d07ec88d16ef521967358af884dafc8fa94b6a9c1cfac4717b6e6a6df4a209ee999ecb4ee9cc7e4ce07b299f1676e601274048f0042e436c41b2208dc012
7
+ data.tar.gz: 4f16f1a94a499726e2aa6e9139866e6a794b78fd13a3ea4f2f7196ff92fdc5c38d5168fd7a79f39b374e1f10a5ecbe723325c641a9217c4b0a9d1d478a547077
data/lib/victoriafresh.rb CHANGED
@@ -9,27 +9,31 @@ require 'digest'
9
9
  # require File.dirname(__FILE__)+'/VictoriaFreSh/filemessage_pb.rb'
10
10
 
11
11
  class VictoriaFresh
12
- attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
13
- attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
14
- attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
15
- attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
16
- attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
12
+ attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
13
+ attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
14
+ attr_accessor :ignoreFileName # 用于指定忽略文件名列表的配置文件的名字
15
+ attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
16
+ attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
17
+ attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
18
+ attr_accessor :timestampThreshold # 文件时间戳阈值。早于这个时间戳的文件不被放入数据块
17
19
 
18
- def initialize
19
- @diskFlush=false #要向磁盘写入文件
20
- @diskFlushSize=143212 #磁盘分块大小
21
- @diskFileName='victoriafreshdata.v' #磁盘文件名
22
- @diskMultiFile=false #磁盘整个文件,不是多个文件
23
- @diskWriteFileObject={} #向磁盘写入文件的对象
24
- @contentString="" #内容字符串
25
- @contentPartArray=[] #内容片段数组
26
- @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
27
- @bufferLength=0 #缓冲区总长度
28
- @externalDataFile={} #外部数据文件对象
29
- @nextFileIdToUse=1 # 下一个要用的文件编号。
30
- @md5FileIdMap={} # MD5 与文件编号之间的映射
31
- @fileIdPathMap={} # 文件编号与它的实际路径之间的映射
32
- end
20
+ def initialize
21
+ @diskFlush=false #要向磁盘写入文件
22
+ @diskFlushSize=143212 #磁盘分块大小
23
+ @diskFileName='victoriafreshdata.v' #磁盘文件名
24
+ @ignoreFileName=nil # 忽略文件名列表配置文件名
25
+ @diskMultiFile=false #磁盘整个文件,不是多个文件
26
+ @diskWriteFileObject={} #向磁盘写入文件的对象
27
+ @contentString="" #内容字符串
28
+ @contentPartArray=[] #内容片段数组
29
+ @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
30
+ @bufferLength=0 #缓冲区总长度
31
+ @externalDataFile={} #外部数据文件对象
32
+ @nextFileIdToUse=1 # 下一个要用的文件编号。
33
+ @md5FileIdMap={} # MD5 与文件编号之间的映射
34
+ @fileIdPathMap={} # 文件编号与它的实际路径之间的映射
35
+ @timestampThreshold=0 # 默认时间戳阈值是0,所有文件都被放入数据块。
36
+ end
33
37
 
34
38
  # 计算文件内容的MD5。
35
39
  def calculateMd5(currentFileContent)
@@ -88,13 +92,6 @@ class VictoriaFresh
88
92
  victoriaFreshData=@externalDataFile.read(packagedFile['file_length']) #读取内容
89
93
  end # if is_duplicate # 是重复文件。
90
94
 
91
- if (packagedFile['name']=='hgrc')
92
- puts packagedFile # Debug
93
- puts victoriaFreshData # Debug
94
- end
95
-
96
-
97
-
98
95
  pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
99
96
 
100
97
  @fileIdPathMap[fileId]=pathToMake # 记录文件编号与路径之间的映射。
@@ -360,125 +357,159 @@ class VictoriaFresh
360
357
  end #if (@diskFlush) #要做磁盘写入
361
358
  end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
362
359
 
360
+ # 读取要忽略的文件名列表。
361
+ def readIgnoreFileList (directoryPathName)
362
+ current_paragraph=[] # 列表
363
+ #陈欣
364
+ datastore= "#{directoryPathName.expand_path}/#{@ignoreFileName}" # 配置文件路径
365
+
366
+ begin
367
+ File.foreach(datastore).with_index do |line, _line_num|
368
+ if line.strip.empty? # 空行
369
+ else # 不是空行
370
+ current_paragraph << line.strip # 记录一行
371
+ end # if line.strip.empty? # 空行
372
+ end # File&.foreach(datastore).with_index do |line, _line_num|
373
+
374
+ rescue Errno::ENOENT
375
+ end
376
+
377
+ current_paragraph
378
+ end
379
+
380
+ def timestampTooEarly(subFile) # 是否文件时间过早。
381
+ result=false # 结果。
382
+ directoryPathName=subFile # 获取路径对象。
383
+ #isFile=directoryPathName.file? #是否是文件。
384
+ #isSymLink=directoryPathName.symlink? #是否是符号链接
385
+ isDirectory=directoryPathName.directory? # 是否是目录。
386
+
387
+ unless isDirectory # 如果是目录就跳过
388
+ #记录时间戳:
389
+ directoryPath=directoryPathName.expand_path # 获取完整路径。
390
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
391
+
392
+ fileTimestamp=mtimeStamp.tv_sec # 获取秒数
393
+
394
+ if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
395
+ result =true # 是过早了
396
+ end # if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
397
+ end # unless isDirectory # 如果是目录就跳过
398
+
399
+ result # 返回结果
400
+ end # def timestampTooEarly(subFile)) # 是否文件时间过早。
401
+
363
402
  def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
364
- if (@diskFlush) #要向磁盘写入文件
365
- if (layer==0) #最外层
366
- if (@diskMultiFile) #要写多个文件
367
- else #不写多个文件
368
- @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
369
- end #if (@diskMultiFile) #要写多个文件
370
- end #if (layer==0) #最外层
371
- end #if (@diskFlush) #要向磁盘写入文件s
403
+ if (@diskFlush) #要向磁盘写入文件
404
+ if (layer==0) #最外层
405
+ if (@diskMultiFile) #要写多个文件
406
+ else #不写多个文件
407
+ @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
408
+ end #if (@diskMultiFile) #要写多个文件
409
+ end #if (layer==0) #最外层
410
+ end #if (@diskFlush) #要向磁盘写入文件s
411
+
412
+ packagedFile={} #创建文件消息对象。
413
+
414
+ directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
415
+
416
+ baseName=directoryPathName.basename.to_s #基本文件名。
417
+
418
+ packagedFile['name']=baseName #设置文件名。
419
+
420
+ isFile=directoryPathName.file? #是否是文件。
421
+ isSymLink=directoryPathName.symlink? #是否是符号链接
422
+
423
+ packagedFile['is_file']=isFile #设置属性,是否是文件。
424
+ packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
425
+
426
+ packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
372
427
 
373
- packagedFile={} #创建文件消息对象。
428
+ #记录时间戳:
429
+ begin #读取时间戳
430
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
374
431
 
375
- directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
432
+ packagedFile['timestamp']={} #时间戳
433
+ packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
434
+ packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
376
435
 
377
- baseName=directoryPathName.basename.to_s #基本文件名。
436
+ packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
437
+ rescue Errno::ENOENT
438
+ rescue Errno::EACCES #权限受限
439
+ end #begin #读取时间戳
378
440
 
379
- packagedFile['name']=baseName #设置文件名。
441
+ if isFile #是文件,不用再列出其子文件了。
442
+ packagedFile['file_length']=0 #记录文件的内容长度。
443
+ packagedFile['id']= nextFileId # 设置下一个文件编号
380
444
 
381
- isFile=directoryPathName.file? #是否是文件。
382
- isSymLink=directoryPathName.symlink? #是否是符号链接
445
+ #读取文件内容:
446
+ fileToReadContent=File.new(directoryPath,"rb") #创建文件。
447
+ currentFileContent=fileToReadContent.read #全部读取
448
+ fileToReadContent.close # 关闭文件
383
449
 
384
- packagedFile['is_file']=isFile #设置属性,是否是文件。
385
- packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
450
+ currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
386
451
 
387
- packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
452
+ sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
388
453
 
389
- #记录时间戳:
390
- begin #读取时间戳
391
- mtimeStamp=File.mtime(directoryPath) #获取时间戳
392
-
393
- packagedFile['timestamp']={} #时间戳
394
- packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
395
- packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
396
-
397
- packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
398
- rescue Errno::ENOENT
399
- rescue Errno::EACCES #权限受限
400
- end #begin #读取时间戳
401
-
402
- if isFile #是文件,不用再列出其子文件了。
403
- packagedFile['file_length']=0 #记录文件的内容长度。
404
- packagedFile['id']= nextFileId # 设置下一个文件编号
405
-
406
- #读取文件内容:
407
- fileToReadContent=File.new(directoryPath,"rb") #创建文件。
408
- currentFileContent=fileToReadContent.read #全部读取
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
436
-
437
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
438
- elsif (isSymLink) #是符号链接
439
- linkTarget=directoryPathName.readlink #获取链接目标
440
-
441
- packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
442
-
443
- #读取文件内容:
444
- # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
445
- currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
446
- @contentPartArray << currentFileContent #加入数组
447
- @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
448
-
449
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
450
- else #是目录。
451
- subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
454
+ if sameFileId.nil? # 不存在相同的文件
455
+ packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
456
+
457
+ @contentPartArray << currentFileContent
458
+ @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
459
+ @md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
460
+ else # 存在相同的文件
461
+ packagedFile['is_duplicate']=true # 是重复文件。
462
+ packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
463
+ end # if sameFileId.nil? # 不存在相同的文件
464
+
465
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
466
+ elsif (isSymLink) #是符号链接
467
+ linkTarget=directoryPathName.readlink #获取链接目标
452
468
 
453
- packagedFile['file_length']=0 #本目录的内容长度。
454
- packagedFile['sub_files'] = [] #加入到子文件列表中。
455
-
456
- directoryPathName.each_child do |subFile| #一个个文件地处理。
457
- begin
458
- realPath=subFile.expand_path #获取绝对路径。
459
-
460
- packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
461
-
462
- packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
463
-
464
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
465
-
466
- subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
467
-
468
- # puts("237, content string length: #{contentString.length}") #Debug
469
-
470
- packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
471
- rescue Errno::EMFILE # File not exist
472
- puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
473
- end
474
- end #directoryPathName.each_child do |subFile| #一个个文件地处理。
475
- end #if (isFile) #是文件,不用再列出其子文件了。
469
+ packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
476
470
 
477
- # puts("300, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
471
+ #读取文件内容:
472
+ # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
473
+ currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
474
+ @contentPartArray << currentFileContent #加入数组
475
+ @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
478
476
 
477
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
478
+ else #是目录。
479
+ subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
480
+
481
+ packagedFile['file_length']=0 #本目录的内容长度。
482
+ packagedFile['sub_files'] = [] #加入到子文件列表中。
479
483
 
480
- # puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
484
+ ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
481
485
 
486
+ directoryPathName.each_child do |subFile| #一个个文件地处理。
487
+ begin
488
+ subFilebaseName=subFile.basename.to_s #基本文件名。
489
+
490
+ if (ignoreFileList.include?(subFilebaseName)) # 是要忽略的文件
491
+ puts "ignore #{subFile}" # 报告,忽略。
492
+ elsif (timestampTooEarly(subFile)) # 文件时间过早。
493
+ puts "ignore #{subFile} early file" # 报告,忽略。
494
+ else # 不忽略
495
+ realPath=subFile.expand_path #获取绝对路径。
496
+
497
+ packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
498
+
499
+ packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
500
+
501
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
502
+
503
+ subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
504
+
505
+ packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
506
+ end
507
+ rescue Errno::EMFILE # too many open Files in process
508
+ puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
509
+ end
510
+ end #directoryPathName.each_child do |subFile| #一个个文件地处理。
511
+ end #if (isFile) #是文件,不用再列出其子文件了。
512
+
482
513
  contentToResult="" #要返回的内容
483
514
 
484
515
  if (layer==0) #是最外层
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: 2022.1.11
4
+ version: 2022.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hxcan Cai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-08 00:00:00.000000000 Z
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hx_cbor