aboutsummaryrefslogtreecommitdiff
path: root/hotline/transaction_handlers.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-28 11:12:00 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-28 11:12:00 -0700
commitdecc2fbf5db4a05aec93462ad35d890930bddd04 (patch)
tree28b15b1cb67eb298657c918faf1a3324bf6da424 /hotline/transaction_handlers.go
parent7f12122f861fab4f4d0e3972ca0e66ff8becae19 (diff)
Implement Make Alias transaction
Diffstat (limited to 'hotline/transaction_handlers.go')
-rw-r--r--hotline/transaction_handlers.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go
index 7e3afa1..ade846e 100644
--- a/hotline/transaction_handlers.go
+++ b/hotline/transaction_handlers.go
@@ -256,6 +256,16 @@ var TransactionHandlers = map[uint16]TransactionType{
Name: "tranSetChatSubject",
Handler: HandleSetChatSubject,
},
+ tranMakeFileAlias: {
+ Access: accessAlwaysAllow,
+ Name: "tranMakeFileAlias",
+ Handler: HandleMakeAlias,
+ RequiredFields: []requiredField{
+ {ID: fieldFileName, minLen: 1},
+ {ID: fieldFilePath, minLen: 1},
+ {ID: fieldFileNewPath, minLen: 1},
+ },
+ },
tranSetClientUserInfo: {
Access: accessAlwaysAllow,
Name: "tranSetClientUserInfo",
@@ -1609,3 +1619,41 @@ func HandleSetChatSubject(cc *ClientConn, t *Transaction) (res []Transaction, er
return res, err
}
+
+// HandleMakeAlias makes a file alias using the specified path.
+// Fields used in the request:
+// 201 File name
+// 202 File path
+// 212 File new path Destination path
+//
+// Fields used in the reply:
+// None
+func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
+ if !authorize(cc.Account.Access, accessMakeAlias) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to make aliases."))
+ return res, err
+ }
+ fileName := t.GetField(fieldFileName).Data
+ filePath := t.GetField(fieldFilePath).Data
+ fileNewPath := t.GetField(fieldFileNewPath).Data
+
+ fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
+ if err != nil {
+ return res, err
+ }
+
+ fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
+ if err != nil {
+ return res, err
+ }
+
+ cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
+
+ if err := FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
+ res = append(res, cc.NewErrReply(t, "Error creating alias"))
+ return res, nil
+ }
+
+ res = append(res, cc.NewReply(t))
+ return res, err
+}