Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
die_coolen_jungs
our_own_cloud_project
Commits
2b89b7c8
Commit
2b89b7c8
authored
11 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
Split scanning logic from ajax file
parent
b397df20
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files/ajax/scan.php
+29
-45
29 additions, 45 deletions
apps/files/ajax/scan.php
lib/eventsource.php
+1
-1
1 addition, 1 deletion
lib/eventsource.php
lib/files/utils/scanner.php
+89
-0
89 additions, 0 deletions
lib/files/utils/scanner.php
with
119 additions
and
46 deletions
apps/files/ajax/scan.php
+
29
−
45
View file @
2b89b7c8
...
...
@@ -16,72 +16,56 @@ if (isset($_GET['users'])) {
}
$eventSource
=
new
OC_EventSource
();
ScanListener
::
$eventSource
=
$eventSource
;
ScanListener
::
$view
=
\OC\Files\Filesystem
::
getView
();
OC_Hook
::
connect
(
'\OC\Files\Cache\Scanner'
,
'scan_folder'
,
'ScanListener'
,
'folder'
);
OC_Hook
::
connect
(
'\OC\Files\Cache\Scanner'
,
'scan_file'
,
'ScanListener'
,
'file'
);
$listener
=
new
ScanListener
(
$eventSource
);
foreach
(
$users
as
$user
)
{
$eventSource
->
send
(
'user'
,
$user
);
OC_Util
::
tearDownFS
();
OC_Util
::
setupFS
(
$user
);
$absolutePath
=
\OC\Files\Filesystem
::
getView
()
->
getAbsolutePath
(
$dir
);
$mountPoints
=
\OC\Files\Filesystem
::
getMountPoints
(
$absolutePath
);
$mountPoints
[]
=
\OC\Files\Filesystem
::
getMountPoint
(
$absolutePath
);
$mountPoints
=
array_reverse
(
$mountPoints
);
//start with the mount point of $dir
foreach
(
$mountPoints
as
$mountPoint
)
{
$storage
=
\OC\Files\Filesystem
::
getStorage
(
$mountPoint
);
if
(
$storage
)
{
ScanListener
::
$mountPoints
[
$storage
->
getId
()]
=
$mountPoint
;
$scanner
=
$storage
->
getScanner
();
if
(
$force
)
{
$scanner
->
scan
(
''
,
\OC\Files\Cache\Scanner
::
SCAN_RECURSIVE
,
\OC\Files\Cache\Scanner
::
REUSE_ETAG
);
}
else
{
$scanner
->
backgroundScan
();
}
}
$scanner
=
new
\OC\Files\Utils\Scanner
(
$user
);
$scanner
->
listen
(
'\OC\Files\Utils\Scanner'
,
'scanFile'
,
array
(
$listener
,
'file'
));
$scanner
->
listen
(
'\OC\Files\Utils\Scanner'
,
'scanFolder'
,
array
(
$listener
,
'folder'
));
if
(
$force
)
{
$scanner
->
scan
(
$dir
);
}
else
{
$scanner
->
backgroundScan
(
$dir
);
}
}
$eventSource
->
send
(
'done'
,
ScanL
istener
::
$file
Count
);
$eventSource
->
send
(
'done'
,
$l
istener
->
get
Count
()
);
$eventSource
->
close
();
class
ScanListener
{
static
public
$fileCount
=
0
;
static
public
$lastCount
=
0
;
private
$fileCount
=
0
;
private
$lastCount
=
0
;
/**
* @var \OC
\Files\View $view
* @var \OC
_EventSource event source to pass events to
*/
static
public
$view
;
private
$eventSource
;
/**
* @
var array $mountPoints map storage ids to mountpoints
* @
param \OC_EventSource $eventSource
*/
static
public
$mountPoints
=
array
();
public
function
__construct
(
$eventSource
)
{
$this
->
eventSource
=
$eventSource
;
}
/**
* @
v
ar
\OC_EventSource event source to pass events to
* @
p
ar
am string $path
*/
static
public
$eventSource
;
static
function
folder
(
$params
)
{
$internalPath
=
$params
[
'path'
];
$mountPoint
=
self
::
$mountPoints
[
$params
[
'storage'
]];
$path
=
self
::
$view
->
getRelativePath
(
$mountPoint
.
$internalPath
);
self
::
$eventSource
->
send
(
'folder'
,
$path
);
public
function
folder
(
$path
)
{
$this
->
eventSource
->
send
(
'folder'
,
$path
);
}
stat
ic
function
file
()
{
self
::
$
fileCount
++
;
if
(
self
::
$
fileCount
>
self
::
$
lastCount
+
20
)
{
//send a count update every 20 files
self
::
$
lastCount
=
self
::
$
fileCount
;
self
::
$
eventSource
->
send
(
'count'
,
self
::
$
fileCount
);
publ
ic
function
file
()
{
$this
->
fileCount
++
;
if
(
$this
->
fileCount
>
$this
->
lastCount
+
20
)
{
//send a count update every 20 files
$this
->
lastCount
=
$this
->
fileCount
;
$this
->
eventSource
->
send
(
'count'
,
$this
->
fileCount
);
}
}
public
function
getCount
()
{
return
$this
->
fileCount
;
}
}
This diff is collapsed.
Click to expand it.
lib/eventsource.php
+
1
−
1
View file @
2b89b7c8
...
...
@@ -53,7 +53,7 @@ class OC_EventSource{
/**
* send a message to the client
* @param string $type
* @param
object
$data
* @param
mixed
$data
*
* if only one parameter is given, a typeless message will be send with that parameter as data
*/
...
...
This diff is collapsed.
Click to expand it.
lib/files/utils/scanner.php
0 → 100644
+
89
−
0
View file @
2b89b7c8
<?php
/**
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace
OC\Files\Utils
;
use
OC\Hooks\BasicEmitter
;
use
OC\Files\Filesystem
;
/**
* Class Scanner
*
* Hooks available in scope \OC\Utils\Scanner
* - scanFile(string $absolutePath)
* - scanFolder(string $absolutePath)
*
* @package OC\Files\Utils
*/
class
Scanner
extends
BasicEmitter
{
/**
* @var string $user
*/
private
$user
;
/**
* @param string $user
*/
public
function
__construct
(
$user
)
{
$this
->
user
=
$user
;
}
/**
* get all storages for $dir
*
* @param string $dir
* @return \OC\Files\Mount\Mount[]
*/
protected
function
getMounts
(
$dir
)
{
//TODO: move to the node based fileapi once that's done
\OC_Util
::
tearDownFS
();
\OC_Util
::
setupFS
(
$this
->
user
);
$absolutePath
=
Filesystem
::
getView
()
->
getAbsolutePath
(
$dir
);
$mountManager
=
Filesystem
::
getMountManager
();
$mounts
=
$mountManager
->
findIn
(
$absolutePath
);
$mounts
[]
=
$mountManager
->
find
(
$absolutePath
);
$mounts
=
array_reverse
(
$mounts
);
//start with the mount of $dir
return
$mounts
;
}
/**
* attach listeners to the scanner
*
* @param \OC\Files\Mount\Mount $mount
*/
protected
function
attachListener
(
$mount
)
{
$scanner
=
$mount
->
getStorage
()
->
getScanner
();
$scanner
->
listen
(
'\OC\Files\Cache\Scanner'
,
'scanFile'
,
function
(
$path
)
use
(
$mount
)
{
$this
->
emit
(
'\OC\Files\Utils\Scanner'
,
'scanFile'
,
array
(
$mount
->
getMountPoint
()
.
$path
));
});
$scanner
->
listen
(
'\OC\Files\Cache\Scanner'
,
'scanFolder'
,
function
(
$path
)
use
(
$mount
)
{
$this
->
emit
(
'\OC\Files\Utils\Scanner'
,
'scanFolder'
,
array
(
$mount
->
getMountPoint
()
.
$path
));
});
}
public
function
backgroundScan
(
$dir
)
{
$mounts
=
$this
->
getMounts
(
$dir
);
foreach
(
$mounts
as
$mount
)
{
$scanner
=
$mount
->
getStorage
()
->
getScanner
();
$this
->
attachListener
(
$mount
);
$scanner
->
backgroundScan
();
}
}
public
function
scan
(
$dir
)
{
$mounts
=
$this
->
getMounts
(
$dir
);
foreach
(
$mounts
as
$mount
)
{
$scanner
=
$mount
->
getStorage
()
->
getScanner
();
$this
->
attachListener
(
$mount
);
$scanner
->
scan
(
''
,
\OC\Files\Cache\Scanner
::
SCAN_RECURSIVE
,
\OC\Files\Cache\Scanner
::
REUSE_ETAG
);
}
}
}
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