Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ea0e6d98
Commit
ea0e6d98
authored
Aug 15, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/FileSystem: RemoveFile() throws exception on error
parent
14d3da0e
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
19 deletions
+45
-19
PlaylistFile.cxx
src/PlaylistFile.cxx
+9
-2
ServerSocket.cxx
src/event/ServerSocket.cxx
+1
-1
FileSystem.cxx
src/fs/FileSystem.cxx
+12
-0
FileSystem.hxx
src/fs/FileSystem.hxx
+4
-10
FileOutputStream.cxx
src/fs/io/FileOutputStream.cxx
+10
-0
FifoOutputPlugin.cxx
src/output/plugins/FifoOutputPlugin.cxx
+4
-4
Daemon.cxx
src/unix/Daemon.cxx
+4
-1
PidFile.hxx
src/unix/PidFile.hxx
+1
-1
No files found.
src/PlaylistFile.cxx
View file @
ea0e6d98
...
@@ -321,8 +321,15 @@ spl_delete(const char *name_utf8)
...
@@ -321,8 +321,15 @@ spl_delete(const char *name_utf8)
const
auto
path_fs
=
spl_map_to_fs
(
name_utf8
);
const
auto
path_fs
=
spl_map_to_fs
(
name_utf8
);
assert
(
!
path_fs
.
IsNull
());
assert
(
!
path_fs
.
IsNull
());
if
(
!
RemoveFile
(
path_fs
))
try
{
ThrowPlaylistErrno
();
RemoveFile
(
path_fs
);
}
catch
(
const
std
::
system_error
&
e
)
{
if
(
IsFileNotFound
(
e
))
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_LIST
,
"No such playlist"
);
else
throw
;
}
idle_add
(
IDLE_STORED_PLAYLIST
);
idle_add
(
IDLE_STORED_PLAYLIST
);
}
}
...
...
src/event/ServerSocket.cxx
View file @
ea0e6d98
...
@@ -426,7 +426,7 @@ ServerSocket::AddPath(AllocatedPath &&path, Error &error)
...
@@ -426,7 +426,7 @@ ServerSocket::AddPath(AllocatedPath &&path, Error &error)
#ifdef HAVE_UN
#ifdef HAVE_UN
(
void
)
error
;
(
void
)
error
;
RemoveFile
(
path
);
unlink
(
path
.
c_str
()
);
AllocatedSocketAddress
address
;
AllocatedSocketAddress
address
;
address
.
SetLocal
(
path
.
c_str
());
address
.
SetLocal
(
path
.
c_str
());
...
...
src/fs/FileSystem.cxx
View file @
ea0e6d98
...
@@ -66,3 +66,15 @@ TruncateFile(Path path)
...
@@ -66,3 +66,15 @@ TruncateFile(Path path)
close
(
fd
);
close
(
fd
);
#endif
#endif
}
}
void
RemoveFile
(
Path
path
)
{
#ifdef WIN32
if
(
!
DeleteFile
(
path
.
c_str
()))
throw
FormatLastError
(
"Failed to delete %s"
,
path
.
c_str
());
#else
if
(
unlink
(
path
.
c_str
())
<
0
)
throw
FormatErrno
(
"Failed to delete %s"
,
path
.
c_str
());
#endif
}
src/fs/FileSystem.hxx
View file @
ea0e6d98
...
@@ -100,17 +100,11 @@ void
...
@@ -100,17 +100,11 @@ void
TruncateFile
(
Path
path
);
TruncateFile
(
Path
path
);
/**
/**
* Wrapper for unlink() that uses #Path names.
* Wrapper for unlink() that uses #Path names. Throws
* std::system_error on error.
*/
*/
static
inline
bool
void
RemoveFile
(
Path
file
)
RemoveFile
(
Path
path
);
{
#ifdef WIN32
return
_tunlink
(
file
.
c_str
())
==
0
;
#else
return
unlink
(
file
.
c_str
())
==
0
;
#endif
}
/**
/**
* Wrapper for readlink() that uses #Path names.
* Wrapper for readlink() that uses #Path names.
...
...
src/fs/io/FileOutputStream.cxx
View file @
ea0e6d98
...
@@ -76,7 +76,11 @@ FileOutputStream::Cancel()
...
@@ -76,7 +76,11 @@ FileOutputStream::Cancel()
assert
(
IsDefined
());
assert
(
IsDefined
());
Close
();
Close
();
try
{
RemoveFile
(
GetPath
());
RemoveFile
(
GetPath
());
}
catch
(
std
::
runtime_error
)
{
}
}
}
#else
#else
...
@@ -153,7 +157,10 @@ FileOutputStream::Commit()
...
@@ -153,7 +157,10 @@ FileOutputStream::Commit()
#if HAVE_LINKAT
#if HAVE_LINKAT
if
(
is_tmpfile
)
{
if
(
is_tmpfile
)
{
try
{
RemoveFile
(
GetPath
());
RemoveFile
(
GetPath
());
}
catch
(
std
::
runtime_error
)
{
}
/* hard-link the temporary file to the final path */
/* hard-link the temporary file to the final path */
char
fd_path
[
64
];
char
fd_path
[
64
];
...
@@ -186,7 +193,10 @@ FileOutputStream::Cancel()
...
@@ -186,7 +193,10 @@ FileOutputStream::Cancel()
#ifdef HAVE_LINKAT
#ifdef HAVE_LINKAT
if
(
!
is_tmpfile
)
if
(
!
is_tmpfile
)
#endif
#endif
try
{
RemoveFile
(
GetPath
());
RemoveFile
(
GetPath
());
}
catch
(
std
::
runtime_error
)
{
}
}
}
#endif
#endif
...
...
src/output/plugins/FifoOutputPlugin.cxx
View file @
ea0e6d98
...
@@ -87,10 +87,10 @@ FifoOutput::Delete()
...
@@ -87,10 +87,10 @@ FifoOutput::Delete()
FormatDebug
(
fifo_output_domain
,
FormatDebug
(
fifo_output_domain
,
"Removing FIFO
\"
%s
\"
"
,
path_utf8
.
c_str
());
"Removing FIFO
\"
%s
\"
"
,
path_utf8
.
c_str
());
if
(
!
RemoveFile
(
path
))
{
try
{
FormatErrno
(
fifo_output_domain
,
RemoveFile
(
path
);
"Could not remove FIFO
\"
%s
\"
"
,
}
catch
(
const
std
::
runtime_error
&
e
)
{
path_utf8
.
c_str
()
);
LogError
(
e
,
"Could not remove FIFO"
);
return
;
return
;
}
}
...
...
src/unix/Daemon.cxx
View file @
ea0e6d98
...
@@ -22,7 +22,10 @@
...
@@ -22,7 +22,10 @@
#include "system/FatalError.hxx"
#include "system/FatalError.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx"
#include "fs/FileSystem.hxx"
#ifndef WIN32
#include "PidFile.hxx"
#include "PidFile.hxx"
#endif
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -247,7 +250,7 @@ void
...
@@ -247,7 +250,7 @@ void
daemonize_finish
(
void
)
daemonize_finish
(
void
)
{
{
if
(
!
pidfile
.
IsNull
())
{
if
(
!
pidfile
.
IsNull
())
{
RemoveFile
(
pidfile
);
unlink
(
pidfile
.
c_str
()
);
pidfile
=
AllocatedPath
::
Null
();
pidfile
=
AllocatedPath
::
Null
();
}
}
...
...
src/unix/PidFile.hxx
View file @
ea0e6d98
...
@@ -64,7 +64,7 @@ public:
...
@@ -64,7 +64,7 @@ public:
assert
(
!
path
.
IsNull
());
assert
(
!
path
.
IsNull
());
close
(
fd
);
close
(
fd
);
RemoveFile
(
path
);
unlink
(
path
.
c_str
()
);
}
}
void
Write
(
pid_t
pid
)
{
void
Write
(
pid_t
pid
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment