Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
BRIC
dokuwiki
Commits
90eb8392
Commit
90eb8392
authored
19 years ago
by
andi
Browse files
Options
Downloads
Patches
Plain Diff
added file locking support
darcs-hash:20050626161253-9977f-5600ca7134aa7244b08407d5a44c065a34091f20.gz
parent
896a5c22
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
inc/io.php
+45
-0
45 additions, 0 deletions
inc/io.php
with
45 additions
and
0 deletions
inc/io.php
+
45
−
0
View file @
90eb8392
...
...
@@ -57,6 +57,7 @@ function io_readFile($file){
*/
function
io_saveFile
(
$file
,
$content
){
io_makeFileDir
(
$file
);
io_lock
(
$file
);
if
(
substr
(
$file
,
-
3
)
==
'.gz'
){
$fh
=
@
gzopen
(
$file
,
'wb9'
);
if
(
!
$fh
){
...
...
@@ -74,9 +75,53 @@ function io_saveFile($file,$content){
fwrite
(
$fh
,
$content
);
fclose
(
$fh
);
}
io_unlock
(
$file
);
return
true
;
}
/**
* Tries to lock a file
*
* Locking is only done for io_savefile and uses directories
* inside $conf['lockdir']
*
* It waits maximal 3 seconds for the lock, after this time
* the lock is assumed to be stale and the function goes on
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function
io_lock
(
$file
){
global
$conf
;
// no locking if safemode hack
if
(
$conf
[
'safemodehack'
])
return
;
$lockDir
=
$conf
[
'lockdir'
]
.
'/'
.
md5
(
$file
);
@
ignore_user_abort
(
1
);
$timeStart
=
time
();
do
{
//waited longer than 3 seconds? -> stale lock
if
((
time
()
-
$timeStart
)
>
3
)
break
;
$locked
=
@
mkdir
(
$lockDir
);
}
while
(
$locked
===
false
);
}
/**
* Unlocks a file
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function
io_unlock
(
$file
){
global
$conf
;
// no locking if safemode hack
if
(
$conf
[
'safemodehack'
])
return
;
$lockDir
=
$conf
[
'lockdir'
]
.
'/'
.
md5
(
$file
);
@
rmdir
(
$lockDir
);
@
ignore_user_abort
(
0
);
}
/**
* Create the directory needed for the given file
*
...
...
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