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
8fb4dfd2
Commit
8fb4dfd2
authored
12 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
use background scanner
parent
ad706229
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files/ajax/scan.php
+57
-32
57 additions, 32 deletions
apps/files/ajax/scan.php
apps/files/js/files.js
+15
-23
15 additions, 23 deletions
apps/files/js/files.js
with
72 additions
and
55 deletions
apps/files/ajax/scan.php
+
57
−
32
View file @
8fb4dfd2
<?php
set_time_limit
(
0
);
//scanning can take ages
session_write_close
();
$force
=
(
isset
(
$_GET
[
'force'
])
and
(
$_GET
[
'force'
]
===
'true'
));
$dir
=
isset
(
$_GET
[
'dir'
])
?
$_GET
[
'dir'
]
:
''
;
$eventSource
=
new
OC_EventSource
();
ScanListener
::
$eventSource
=
$eventSource
;
ScanListener
::
$view
=
\OC\Files\Filesystem
::
getView
();
return
;
OC_Hook
::
connect
(
'\OC\Files\Cache\Scanner'
,
'scan_folder'
,
'ScanListener'
,
'folder'
);
OC_Hook
::
connect
(
'\OC\Files\Cache\Scanner'
,
'scan_file'
,
'ScanListener'
,
'file'
);
set_time_limit
(
0
);
//scanning can take ages
$absolutePath
=
\OC\Files\Filesystem
::
getView
()
->
getAbsolutePath
(
$dir
);
$
force
=
isset
(
$_GET
[
'force'
])
and
$_GET
[
'force'
]
==
'true'
;
$
dir
=
isset
(
$_GET
[
'dir'
])
?
$_GET
[
'dir'
]
:
''
;
$
checkOnly
=
is
se
t
(
$
_GET
[
'checkonly'
])
and
$_GET
[
'checkonly'
]
==
'true'
;
$
mountPoints
=
\OC\Files\Filesystem
::
getMountPoints
(
$absolutePath
)
;
$
mountPoints
[]
=
\OC\Files\Filesystem
::
getMountPoint
(
$absolutePath
)
;
$
mountPoints
=
array_rever
se
(
$
mountPoints
);
//start with the mount point of $dir
if
(
!
$checkOnly
)
{
$eventSource
=
new
OC_EventSource
();
foreach
(
$mountPoints
as
$mountPoint
)
{
$storage
=
\OC\Files\Filesystem
::
getStorage
(
$mountPoint
);
error_log
(
'scanning mp '
.
$mountPoint
);
ScanListener
::
$mountPoints
[
$storage
->
getId
()]
=
$mountPoint
;
$scanner
=
$storage
->
getScanner
();
if
(
$force
)
{
$scanner
->
scan
(
''
);
}
else
{
$scanner
->
backgroundScan
();
}
}
session_write_close
();
$eventSource
->
send
(
'done'
,
ScanListener
::
$fileCount
);
$eventSource
->
close
();
//create the file cache if necesary
if
(
$force
or
!
OC_FileCache
::
inCache
(
''
))
{
if
(
!
$checkOnly
)
{
OCP\DB
::
beginTransaction
();
class
ScanListener
{
if
(
OC_Cache
::
isFast
())
{
OC_Cache
::
clear
(
'fileid/'
);
//make sure the old fileid's don't mess things up
}
static
public
$fileCount
=
0
;
static
public
$lastCount
=
0
;
OC_FileCache
::
scan
(
$dir
,
$eventSource
);
OC_FileCache
::
clean
();
OCP\DB
::
commit
();
$eventSource
->
send
(
'success'
,
true
);
}
else
{
OCP\JSON
::
success
(
array
(
'data'
=>
array
(
'done'
=>
true
)));
exit
;
}
}
else
{
if
(
$checkOnly
)
{
OCP\JSON
::
success
(
array
(
'data'
=>
array
(
'done'
=>
false
)));
exit
;
/**
* @var \OC\Files\View $view
*/
static
public
$view
;
/**
* @var array $mountPoints map storage ids to mountpoints
*/
static
public
$mountPoints
=
array
();
/**
* @var \OC_EventSource event source to pass events to
*/
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
);
}
if
(
isset
(
$eventSource
))
{
$eventSource
->
send
(
'success'
,
false
);
}
else
{
exit
;
static
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
);
}
}
}
$eventSource
->
close
();
This diff is collapsed.
Click to expand it.
apps/files/js/files.js
+
15
−
23
View file @
8fb4dfd2
...
...
@@ -602,12 +602,8 @@ $(document).ready(function() {
});
});
//check if we need to scan the filesystem
$
.
get
(
OC
.
filePath
(
'
files
'
,
'
ajax
'
,
'
scan.php
'
),{
checkonly
:
'
true
'
},
function
(
response
)
{
if
(
response
.
data
.
done
){
scanFiles
();
}
},
"
json
"
);
//do a background scan if needed
scanFiles
();
var
lastWidth
=
0
;
var
breadcrumbs
=
[];
...
...
@@ -676,27 +672,23 @@ $(document).ready(function() {
resizeBreadcrumbs
(
true
);
});
function
scanFiles
(
force
,
dir
){
function
scanFiles
(
force
,
dir
){
if
(
!
dir
){
dir
=
''
;
dir
=
''
;
}
force
=
!!
force
;
//cast to bool
scanFiles
.
scanning
=
true
;
$
(
'
#
scann
ing-message
'
).
show
(
);
$
(
'
#fileList
'
).
remove
(
);
var
scannerEventSource
=
new
OC
.
EventSource
(
OC
.
filePath
(
'
files
'
,
'
ajax
'
,
'
scan.php
'
),{
force
:
force
,
dir
:
dir
});
scanFiles
.
cancel
=
scannerEventSource
.
close
.
bind
(
scannerEventSource
);
scannerEventSource
.
listen
(
'
scanning
'
,
function
(
data
){
$
(
'
#scan-count
'
).
text
(
t
(
'
files
'
,
'
{count} files scanned
'
,
{
count
:
data
.
count
}));
$
(
'
#scan-current
'
).
text
(
data
.
file
+
'
/
'
);
force
=
!!
force
;
//cast to bool
scanFiles
.
scanning
=
true
;
var
scann
erEventSource
=
new
OC
.
EventSource
(
OC
.
filePath
(
'
files
'
,
'
ajax
'
,
'
scan.php
'
),{
force
:
force
,
dir
:
dir
}
);
scanFiles
.
cancel
=
scannerEventSource
.
close
.
bind
(
scannerEventSource
);
scannerEventSource
.
listen
(
'
count
'
,
function
(
count
){
console
.
log
(
count
+
'
files scanned
'
)
});
scannerEventSource
.
listen
(
'
folder
'
,
function
(
path
){
console
.
log
(
'
now scanning
'
+
path
)
});
scannerEventSource
.
listen
(
'
success
'
,
function
(
success
){
scannerEventSource
.
listen
(
'
done
'
,
function
(
count
){
scanFiles
.
scanning
=
false
;
if
(
success
){
window
.
location
.
reload
();
}
else
{
alert
(
t
(
'
files
'
,
'
error while scanning
'
));
}
console
.
log
(
'
done after
'
+
count
+
'
files
'
);
});
}
scanFiles
.
scanning
=
false
;
...
...
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