3
// Copyright (C) 2008 - 2010 Patrick Ulbrich
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using Platform.Unix.IO;
23
namespace Platform.Common.IO
25
// required to be in sync with Platform.Unix.IO.UnixFileType
37
public static class FileHelper
39
public static FileType GetFileType(string path, bool followSymLinks) {
41
// TODO : test me, is it working?
42
System.IO.FileAttributes attr = System.IO.File.GetAttributes(path);
43
return (attr & System.IO.FileAttributes.Directory) != 0 ? FileType.Directory : FileType.RegularFile;
45
Mono.Unix.Native.Stat stat;
47
stat = UnixFileHelper.GetStat(path);
49
stat = UnixFileHelper.GetLStat(path);
52
UnixFileType uft = UnixFileHelper.GetFileType(stat);
54
case UnixFileType.Directory:
55
ft = FileType.Directory;
57
case UnixFileType.CharacterDevice:
58
ft = FileType.CharacterDevice;
60
case UnixFileType.BlockDevice:
61
ft = FileType.BlockDevice;
63
case UnixFileType.RegularFile:
64
ft = FileType.RegularFile;
66
case UnixFileType.Fifo:
69
case UnixFileType.SymbolicLink:
70
ft = FileType.SymbolicLink;
72
case UnixFileType.Socket:
76
throw new NotImplementedException(string.Format("UnixFileType {0} has no equivalent FileType value yet", uft.ToString()));
82
public static string GetCanonicalSymLinkTarget(string symLinkPath) {
84
throw new NotImplementedException();
86
return UnixFileHelper.ReadLink(symLinkPath, true);