-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Unbewohnte
committed
Jan 22, 2022
1 parent
700811b
commit 8eb2f18
Showing
10 changed files
with
277 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
ftu - file transferring utility. | ||
Copyright (C) 2021,2022 Kasyanov Nikolay Alexeevich (Unbewohnte (https://unbewohnte.xyz/)) | ||
This file is a part of ftu | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package fsys | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Symlink struct { | ||
TargetPath string | ||
Path string | ||
} | ||
|
||
// Checks whether path is referring to a symlink or not | ||
func IsSymlink(path string) (bool, error) { | ||
stats, err := os.Lstat(path) | ||
if err != nil { | ||
return false, err | ||
} | ||
isSymlink := stats.Mode()&os.ModeSymlink != 0 | ||
|
||
return isSymlink, nil | ||
} | ||
|
||
var ErrorNotSymlink error = fmt.Errorf("not a symlink") | ||
|
||
// get necessary information about a symlink in a filesystem. If check is false - | ||
// does not check if path REALLY refers to a symlink | ||
func GetSymlink(path string, check bool) (*Symlink, error) { | ||
if check { | ||
isSymlink, err := IsSymlink(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !isSymlink { | ||
return nil, ErrorNotSymlink | ||
} | ||
} | ||
|
||
target, err := os.Readlink(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
symlink := Symlink{ | ||
TargetPath: target, | ||
Path: path, | ||
} | ||
|
||
return &symlink, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fsys | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func Test_IsSymlink(t *testing.T) { | ||
dirpath := "../testfiles/" | ||
|
||
symlinkPath := filepath.Join(dirpath, "testsymlink.txt") | ||
os.Symlink(filepath.Join(dirpath, "testfile.txt"), symlinkPath) | ||
|
||
isSymlink, err := IsSymlink(symlinkPath) | ||
if err != nil { | ||
t.Fatalf("%s\n", err) | ||
} | ||
if !isSymlink { | ||
t.Fatalf("%s expected to be a symlink\n", symlinkPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ import ( | |
) | ||
|
||
var ( | ||
VERSION string = "v2.2.3" | ||
VERSION string = "v2.3.0" | ||
|
||
versionInformation string = fmt.Sprintf("ftu %s\nfile transferring utility\n\nCopyright (C) 2021,2022 Kasyanov Nikolay Alexeevich (Unbewohnte ([email protected]))\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions; type \"ftu -l\" for details.\n", VERSION) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.