Debian Codegraph @

CodeLite/cl_sftp_attribute.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : cl_sftp_attribute.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #if USE_SFTP
27
28 #include "cl_sftp_attribute.h"
29 #include <libssh/sftp.h>
30
31 SFTPAttribute::SFTPAttribute(SFTPAttribute_t attr)
32 : m_attributes(NULL)
33 , m_permissions(0)
34 {
35 Assign(attr);
36 }
37
38 SFTPAttribute::~SFTPAttribute() { DoClear(); }
39
40 void SFTPAttribute::Assign(SFTPAttribute_t attr)
41 {
42 DoClear();
43 m_attributes = attr;
44 DoConstruct();
45 }
46
47 void SFTPAttribute::DoClear()
48 {
49 if(m_attributes) {
50 sftp_attributes_free(m_attributes);
51 }
52 m_attributes = NULL;
53 m_name.Clear();
54 m_flags = 0;
55 m_size = 0;
56 m_permissions = 0;
57 }
58
59 void SFTPAttribute::DoConstruct()
60 {
61 if(!m_attributes)
62 return;
63
64 m_name = m_attributes->name;
65 m_size = m_attributes->size;
66 m_permissions = m_attributes->permissions;
67 m_flags = 0;
68
69 switch(m_attributes->type) {
70 case SSH_FILEXFER_TYPE_DIRECTORY:
71 m_flags |= TYPE_FOLDER;
72 break;
73 default:
74 case SSH_FILEXFER_TYPE_REGULAR:
75 m_flags |= TYPE_REGULAR_FILE;
76 break;
77 case SSH_FILEXFER_TYPE_SPECIAL:
78 m_flags |= TYPE_SEPCIAL;
79 break;
80
81 case SSH_FILEXFER_TYPE_UNKNOWN:
82 m_flags |= TYPE_UNKNOWN;
83 break;
84
85 case SSH_FILEXFER_TYPE_SYMLINK:
86 m_flags |= TYPE_SYMBLINK;
87 break;
88 }
89 }
90
91 wxString SFTPAttribute::GetTypeAsString() const
92 {
93 if(IsSymlink()) {
94 if(IsFolder()) {
95 return " -> " + GetSymlinkPath();
96 } else if(IsFile()) {
97 return " -> " + GetSymlinkPath();
98 } else {
99 return "Symlink";
100 }
101 } else {
102 if(IsSpecial()) {
103 return "Special";
104 } else if(IsFolder()) {
105 return "Folder";
106 } else if(IsFile()) {
107 return "File";
108 } else {
109 return "Unknown";
110 }
111 }
112 }
113
114 bool SFTPAttribute::Compare(SFTPAttribute::Ptr_t one, SFTPAttribute::Ptr_t two)
115 {
116 if(one->IsFolder() && !two->IsFolder()) {
117 return true;
118
119 } else if(!one->IsFolder() && two->IsFolder()) {
120 return false;
121
122 } else {
123 return one->GetName() < two->GetName();
124 }
125 }
126
127 #endif // USE_SFTP