Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
maarchRM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
maarchRM
Commits
5f3f5fcd
Verified
Commit
5f3f5fcd
authored
6 years ago
by
Cyril Vazquez
Browse files
Options
Downloads
Patches
Plain Diff
Manage compressed folders
parent
35189ef9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dependency/repository/Adapter/fileSystem/Repository.php
+106
-38
106 additions, 38 deletions
dependency/repository/Adapter/fileSystem/Repository.php
with
106 additions
and
38 deletions
dependency/repository/Adapter/fileSystem/Repository.php
+
106
−
38
View file @
5f3f5fcd
...
@@ -358,18 +358,28 @@ class Repository
...
@@ -358,18 +358,28 @@ class Repository
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
if
(
!
file_exists
(
$filename
))
{
if
(
!
file_exists
(
$filename
))
{
return
false
;
return
$this
->
checkCompressedFile
(
$path
)
;
}
}
return
true
;
return
true
;
}
}
protected
function
checkCompressedFile
(
$path
)
{
list
(
$zipfile
,
$filename
)
=
$this
->
getCompressedPathinfo
(
$path
);
$zip
=
\laabs
::
newService
(
'dependency/fileSystem/plugins/zip'
);
$compressedFiles
=
$zip
->
contents
(
$zipfile
);
return
in_array
(
$filename
,
$compressedFiles
);
}
protected
function
readFile
(
$path
)
protected
function
readFile
(
$path
)
{
{
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
if
(
!
file_exists
(
$filename
))
{
if
(
!
file_exists
(
$filename
))
{
throw
new
\Exception
(
"Can not find resource at path
$path
"
);
return
$this
->
readCompressedFile
(
$path
);
}
}
if
(
!
$data
=
file_get_contents
(
$filename
))
{
if
(
!
$data
=
file_get_contents
(
$filename
))
{
...
@@ -379,6 +389,51 @@ class Repository
...
@@ -379,6 +389,51 @@ class Repository
return
$data
;
return
$data
;
}
}
protected
function
readCompressedFile
(
$path
)
{
list
(
$zipfile
,
$filename
)
=
$this
->
getCompressedPathinfo
(
$path
);
$tmpdir
=
\laabs
::
getTmpDir
()
.
DIRECTORY_SEPARATOR
.
str_replace
(
','
,
'.'
,
microtime
(
true
))
.
'.'
.
mt_rand
();
$tmpfile
=
$tmpdir
.
DIRECTORY_SEPARATOR
.
basename
(
$filename
);
$zip
=
\laabs
::
newService
(
'dependency/fileSystem/plugins/zip'
);
$zip
->
extract
(
$zipfile
,
$tmpdir
,
$filename
,
null
,
'e'
);
if
(
!
$data
=
file_get_contents
(
$tmpfile
))
{
throw
new
\Exception
(
"Can not read at path
$path
"
);
}
unlink
(
$tmpfile
);
return
$data
;
}
protected
function
getCompressedPathinfo
(
$path
)
{
$steps
=
\laabs\explode
(
DIRECTORY_SEPARATOR
,
$path
);
$filename
=
$this
->
root
;
while
(
$step
=
array_shift
(
$steps
))
{
$filename
.
=
DIRECTORY_SEPARATOR
.
$step
;
switch
(
true
)
{
case
is_dir
(
$filename
)
:
continue
;
case
is_file
(
$filename
.
'.7z'
)
:
return
[
$filename
.
'.7z'
,
$step
.
DIRECTORY_SEPARATOR
.
implode
(
DIRECTORY_SEPARATOR
,
$steps
)];
case
is_file
(
$filename
.
'.zip'
)
:
return
[
$filename
.
'.zip'
,
$step
.
DIRECTORY_SEPARATOR
.
implode
(
DIRECTORY_SEPARATOR
,
$steps
)];
default
:
throw
new
\Exception
(
"Can not find resource at path
$path
"
);
}
}
throw
new
\Exception
(
"Can not find resource at path
$path
"
);
}
protected
function
updateFile
(
$path
,
$data
)
protected
function
updateFile
(
$path
,
$data
)
{
{
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
...
@@ -435,49 +490,16 @@ class Repository
...
@@ -435,49 +490,16 @@ class Repository
}
}
private
function
deleteFile
(
$path
)
private
function
deleteFile
(
$path
)
{
{
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
$filename
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
$path
;
if
(
!
file_exists
(
$filename
))
{
if
(
!
file_exists
(
$filename
))
{
throw
new
\Exception
(
"No resource found at path
$path
"
);
return
$this
->
deleteCompressedFile
(
$path
);
}
}
if
(
$this
->
shred
)
{
if
(
$this
->
shred
)
{
$fp
=
fopen
(
$filename
,
'w'
);
$this
->
shred
(
$filename
);
$fileSize
=
filesize
(
$filename
);
$pass
=
0
;
//while ($pass != 6) {
$randNum
=
rand
(
0
,
255
);
$compNum
=
255
-
$randNum
;
$lastNum
=
-
1
;
do
{
$lastNum
=
rand
(
0
,
255
);
}
while
(
$lastNum
==
$compNum
);
// First pass with random num
$randContents
=
str_repeat
(
chr
(
$randNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$randContents
);
// Second pass with complement of random num
$compContents
=
str_repeat
(
chr
(
$compNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$compContents
);
// Third pass with a new random num
$lastContents
=
str_repeat
(
chr
(
$lastNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$lastContents
);
$pass
++
;
//}
fclose
(
$fp
);
}
}
if
(
!
unlink
(
$filename
))
{
if
(
!
unlink
(
$filename
))
{
throw
new
\Exception
(
"Can not delete at path
$path
"
);
throw
new
\Exception
(
"Can not delete at path
$path
"
);
...
@@ -486,6 +508,52 @@ class Repository
...
@@ -486,6 +508,52 @@ class Repository
return
true
;
return
true
;
}
}
protected
function
deleteCompressedFile
(
$path
)
{
list
(
$zipfile
,
$filename
)
=
$this
->
getCompressedPathinfo
(
$path
);
$zip
=
\laabs
::
newService
(
'dependency/fileSystem/plugins/zip'
);
return
$zip
->
delete
(
$zipfile
,
$filename
);
}
protected
function
shred
(
$filename
)
{
$fp
=
fopen
(
$filename
,
'w'
);
$fileSize
=
filesize
(
$filename
);
$pass
=
0
;
//while ($pass != 6) {
$randNum
=
rand
(
0
,
255
);
$compNum
=
255
-
$randNum
;
$lastNum
=
-
1
;
do
{
$lastNum
=
rand
(
0
,
255
);
}
while
(
$lastNum
==
$compNum
);
// First pass with random num
$randContents
=
str_repeat
(
chr
(
$randNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$randContents
);
// Second pass with complement of random num
$compContents
=
str_repeat
(
chr
(
$compNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$compContents
);
// Third pass with a new random num
$lastContents
=
str_repeat
(
chr
(
$lastNum
),
$fileSize
);
fseek
(
$fp
,
0
);
fwrite
(
$fp
,
$lastContents
);
$pass
++
;
//}
fclose
(
$fp
);
}
protected
function
writeMetadata
(
$path
,
$metadata
)
protected
function
writeMetadata
(
$path
,
$metadata
)
{
{
$dir
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
dirname
(
$path
);
$dir
=
$this
->
root
.
DIRECTORY_SEPARATOR
.
dirname
(
$path
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment